Skip to content

Latest commit

 

History

History
78 lines (64 loc) · 1.27 KB

README.md

File metadata and controls

78 lines (64 loc) · 1.27 KB

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
	}
}