digest

package
v2.11.4 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package digest provides authentication strategy, to authenticate HTTP requests using the standard digest scheme as described in RFC 7616.

Index

Constants

This section is empty.

Variables

View Source
var ErrInavlidHeader = errors.New("strategies/digest: Invalid Authorization Header")

ErrInavlidHeader is returned by Header parse when authz header is not digest.

View Source
var ErrInvalidResponse = errors.New("strategies/digest: Invalid Response")

ErrInvalidResponse is returned by Strategy when client authz response does not match server hash.

Functions

func SetHash

func SetHash(h crypto.Hash, algorithm string) auth.Option

SetHash set the hashing algorithm to hash the user password. Default md5

SetHash(crypto.SHA1, "sha1")

func SetOpaque

func SetOpaque(opaque string) auth.Option

SetOpaque set digest opaque. Default random generated key.

func SetRealm

func SetRealm(realm string) auth.Option

SetRealm set digest authentication realm. Default "Users".

Types

type Digest

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

Digest authentication strategy.

func New

func New(f FetchUser, c auth.Cache, opts ...auth.Option) *Digest

New returns digest authentication strategy. Digest strategy use MD5 as default hash. Digest use cache to store nonce.

func (*Digest) Authenticate

func (d *Digest) Authenticate(ctx context.Context, r *http.Request) (auth.Info, error)

Authenticate user request and returns user info, Otherwise error.

func (*Digest) GetChallenge

func (d *Digest) GetChallenge() string

GetChallenge returns string indicates the authentication scheme. Typically used to adds a HTTP WWW-Authenticate header.

type FetchUser

type FetchUser func(userName string) (string, auth.Info, error)

FetchUser a callback function to return the user password and user info.

type Header map[string]string

Header represents The Authorization Header Field, and WWW-Authenticate Response Header Field as described in RFC 7616

func (Header) Algorithm

func (h Header) Algorithm() string

Algorithm return a string indicating an hash algorithm used to produce the digest and an unkeyed digest.

func (Header) Clone

func (h Header) Clone() Header

Clone returns a copy of h or nil if h is nil.

func (Header) Cnonce

func (h Header) Cnonce() string

Cnonce returns string of client nounce.

func (Header) Compare

func (h Header) Compare(ch Header) error

Compare server header vs client header returns error if any diff found.

func (Header) NC

func (h Header) NC() string

NC returns nonce count.

func (Header) Nonce

func (h Header) Nonce() string

Nonce A string of hex represents uniquely generated key of 16 byte.

func (Header) Opaque

func (h Header) Opaque() string

Opaque A string of hex represents uniquely generated key of 16 byte.

func (Header) Parse

func (h Header) Parse(authorization string) error

Parse The Authorization Header string.

func (Header) QOP

func (h Header) QOP() string

QOP returns quality of protection e.g auth.

func (Header) Realm

func (h Header) Realm() string

Realm return a string to be displayed to users so they know which username and password to use. See https://tools.ietf.org/html/rfc7616#section-3.3

func (Header) Response

func (h Header) Response() string

Response returns A string of the hex digits computed by client.

func (Header) SetAlgorithm

func (h Header) SetAlgorithm(a string)

SetAlgorithm sets hash algorithm.

func (Header) SetCnonce

func (h Header) SetCnonce(cn string)

SetCnonce sets the client nounce.

func (Header) SetNC

func (h Header) SetNC(n string)

SetNC set nonce count.

func (Header) SetNonce

func (h Header) SetNonce(n string)

SetNonce sets the nounce.

func (Header) SetOpaque

func (h Header) SetOpaque(o string)

SetOpaque sets the opaque.

func (Header) SetQOP

func (h Header) SetQOP(q string)

SetQOP sets the QOP.

func (Header) SetRealm

func (h Header) SetRealm(r string)

SetRealm sets the realm.

func (Header) SetResponse

func (h Header) SetResponse(r string)

SetResponse sets the client response.

func (Header) SetURI

func (h Header) SetURI(u string)

SetURI sets Effective Request URI.

func (Header) SetUserName

func (h Header) SetUserName(u string)

SetUserName sets user name.

func (Header) String

func (h Header) String() string

String describe header as a string

func (Header) URI

func (h Header) URI() string

URI return Effective Request URI See https://tools.ietf.org/html/rfc7230#section-5.5

func (Header) UserName

func (h Header) UserName() string

UserName return the The user's name in the specified realm.

func (Header) WWWAuthenticate

func (h Header) WWWAuthenticate() string

WWWAuthenticate return string represents HTTP WWW-Authenticate header field with Digest scheme.

Jump to

Keyboard shortcuts

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