Skip to content

telebroad/digest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Digest

it's a go implementation for digest auth

Download

go get github.com/telebroad/digest

DEMOS

Basic example

package main

import (
	"fmt"
	"github.com/telebroad/digest"
)

var (
	method    = "POST"
	host      = "https://www.example.com"
	uri       = "/some/route"
	user      = "my-username"
	pass      = "my-password"
	userAgent = "test-user-agent"
)

func main() {
	token, err := digest.Token(method, host, uri, user, pass, userAgent, false)
	if err != nil {
		// handle error
	}

	fmt.Printf("http header token: %s\n",token)
}

more advance

package main

import (
	"bytes"
	"github.com/telebroad/digest"
	"net/http"
)

var (
	method    = "POST"
	host      = "https://www.example.com"
	uri       = "/some/route"
	user      = "my-username"
	pass      = "my-password"
	userAgent = "test-user-agent"
)

func main() {
	Digest, err := digest.New(method, host, uri, user, pass, userAgent, false)
	if err != nil {
		// handle error
	}
	body := bytes.NewBufferString("<body>some example body</body>")
	// this will return http request and append the header to it 
	req, err := Digest.Request(body)
	if err != nil {
		// handle error
	}

	client := &http.Client{}

	resp, err := Digest.Do(client, req, body)
	if err != nil {
		// handle error
	}
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages