digest_auth_client

package module
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2021 License: BSD-2-Clause Imports: 13 Imported by: 2

README

go-http-digest-auth-client

Golang Http Digest Authentication Client

This client implements RFC7616 HTTP Digest Access Authentication and by now the basic features should work.

This implementation presents pluggable HTTP transport with http.RoundTripper interface, stackable on top of other RoundTripper. DigestTransport intercepts server responses requiring Digest authentication and restarts them with Authentication header. Authentication challenge is reused whereever possible and it's expiration (server reject) is handled automatically.

Usage

Complete example from E2E test:


package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"

	dac "github.com/Snawoot/go-http-digest-auth-client"
)

const (
	username = "test"
	password = "test123"
	uri      = "http://172.16.1.5"
)

func main() {
	client := &http.Client{
		Transport: dac.NewDigestTransport(username, password, http.DefaultTransport),
	}

	resp, err := client.Get(uri)
	if err != nil {
		log.Fatalln(err)
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Printf(string(body))
}

Documentation

Index

Constants

View Source
const (
	READ_LIMIT int64 = 128 * 1024
)

Variables

View Source
var (
	AuthRetryNeeded = errors.New("retry request with authentication")
)

Functions

func ParseList added in v1.1.1

func ParseList(value string) []string

ParseList parses a comma-separated list of values as described by RFC 2068 and returns list elements.

Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go which was ported from urllib2.parse_http_list, from the Python standard library.

func ParsePairs added in v1.1.1

func ParsePairs(value string) map[string]string

ParsePairs extracts key/value pairs from a comma-separated list of values as described by RFC 2068 and returns a map[key]value. The resulting values are unquoted. If a list element doesn't contain a "=", the key is the element itself and the value is an empty string.

Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go

Types

type DigestTransport added in v0.2.0

type DigestTransport struct {
	// contains filtered or unexported fields
}

func NewDigestTransport added in v1.0.0

func NewDigestTransport(username, password string, transport http.RoundTripper) *DigestTransport

NewRequest creates a new DigestTransport object

func (*DigestTransport) RoundTrip added in v0.2.0

func (dt *DigestTransport) RoundTrip(req *http.Request) (resp *http.Response, err error)

Execute initialise the request and get a response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL