digest

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2020 License: MIT Imports: 10 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

View Source
const StrategyKey = auth.StrategyKey("Digest.Strategy")

StrategyKey export identifier for the digest strategy, commonly used when enable/add strategy to go-guardian authenticator.

Variables

View Source
var ErrInavlidHeader = errors.New("Digest: Invalid Authorization Header")

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

View Source
var ErrInvalidResponse = errors.New("Digest: Invalid Response")

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

Functions

This section is empty.

Types

type CachedStrategy

type CachedStrategy struct {
	*Strategy
	Cache store.Cache
}

CachedStrategy caches digest strategy authentication response based on authorization nonce field.

func (*CachedStrategy) Authenticate

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

Authenticate user request and returns user info, Otherwise error.

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) Cnonce

func (h Header) Cnonce() string

Cnonce returns string of client nounce.

func (Header) Compare added in v1.2.1

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 added in v1.2.1

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, error)

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

type Strategy

type Strategy struct {
	// Hash a callback function to return the desired hash algorithm,
	// the passed algo args is extracted from authorization header
	// and if it missing the args will be same as algorithm field provided to the strategy.
	Hash func(algo string) hash.Hash

	// FetchUser a callback function to return the user password and user info or error in case of occurs.
	FetchUser func(userName string) (string, auth.Info, error)

	Realm     string
	Algorithm string
}

Strategy implements auth.Strategy and represents digest authentication as described in RFC 7616.

func (*Strategy) Authenticate

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

Authenticate user request and returns user info, Otherwise error.

func (*Strategy) Challenge added in v1.2.2

func (s *Strategy) Challenge(realm string) string

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

func (*Strategy) WWWAuthenticate

func (s *Strategy) WWWAuthenticate(hh http.Header) error

WWWAuthenticate set 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