authenticate

package
v0.0.52 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AuthSchemeNTLM represents an NTLM authorization.
	AuthSchemeNTLM = AuthSchemeNegotiate
)

Variables

This section is empty.

Functions

func WriteResponse

func WriteResponse(resp http.ResponseWriter, auth Authenticator)

WriteResponse writes the WWW-Authenticate header to the provided HTTP response.

Types

type AuthDecoder

type AuthDecoder interface {
	Decode(req *http.Request) (string, bool)
}

type AuthScheme

type AuthScheme int

AuthScheme represents the type of authorization.

const (
	// AuthSchemeAnonymous represents an anonymous authorization.
	AuthSchemeAnonymous AuthScheme = iota
	// AuthSchemeBasic represents a basic authorization.
	AuthSchemeBasic
	// AuthSchemeBearer represents a bearer authorization.
	AuthSchemeBearer
	// AuthSchemeDigest represents a digest authorization.
	AuthSchemeDigest
	// AuthSchemeHOBA represents a HTTP Origin-Bound Authentication (HOBA) authorization.
	AuthSchemeHOBA
	// AuthSchemeMutual represents a mutual authentication.
	AuthSchemeMutual
	// AuthSchemeNegotiate represents a negotiate authorization.
	AuthSchemeNegotiate
	// AuthSchemeVapid represents a VAPID authorization.
	AuthSchemeVapid
	// AuthSchemeSCRAM represents a SCRAM authorization.
	AuthSchemeSCRAM
	// AuthSchemeAWS4HMAC256 represents an AWS4-HMAC-SHA256 authorization.
	AuthSchemeAWS4HMAC256
	// AuthSchemeDPoP represents a DPoP authorization.
	AuthSchemeDPoP
	// AuthSchemeGNAP represents a GNAP authorization.
	AuthSchemeGNAP
	// AuthSchemePrivate represents a private authorization.
	AuthSchemePrivate
	// AuthSchemeOAuth represents an OAuth authorization.
	AuthSchemeOAuth
	// AuthSchemeUnknown represents an unknown authorization.
	AuthSchemeUnknown
)

func (AuthScheme) Equal

func (t AuthScheme) Equal(other string) bool

func (AuthScheme) Lower

func (t AuthScheme) Lower() string

Lower returns the lowercase string representation of the Type.

func (AuthScheme) String

func (i AuthScheme) String() string

type Authenticator

type Authenticator interface {
	Scheme() AuthScheme
	Credentials() string
	Extra() []string
	Encode(args ...any) (string, error)
}

func ParseAuth

func ParseAuth(auth string) (Authenticator, bool)

ParseAuth parses the authorization and returns an authenticate struct with the type and credentials extracted. If the header is empty, it returns TypeUnknown with the provided auth string and false. If the header contains only one token, it returns TypeAnonymous with the token as credentials and true. For headers with multiple tokens, it checks the type (basic, bearer, digest) and returns the corresponding to authenticate struct with the credentials and true. If the type is not recognized, it returns TypeUnknown with the original auth string and false.

func ParseRequest

func ParseRequest(req *http.Request) (Authenticator, bool)

ParseRequest parses the Authorization header from the provided HTTP request. If the header is empty, it returns nil and false.

type AuthorizationDecoder

type AuthorizationDecoder struct {
	Key string
}

AuthorizationDecoder decodes the "Authorization" header.

func (*AuthorizationDecoder) Decode

func (ad *AuthorizationDecoder) Decode(req *http.Request) (string, bool)

Decode implements the AuthDecoder interface.

type CookieDecoder

type CookieDecoder struct {
	Key string
}

CookieDecoder decodes the cookies.

func (*CookieDecoder) Decode

func (cd *CookieDecoder) Decode(req *http.Request) (string, bool)

Decode implements the AuthDecoder interface.

type FormDecoder

type FormDecoder struct {
	Key       string
	MaxMemory int64
}

func (*FormDecoder) Decode

func (fd *FormDecoder) Decode(req *http.Request) (string, bool)

Decode implements the AuthDecoder interface.

type ParamDecoder

type ParamDecoder struct {
	Key string
}

func (*ParamDecoder) Decode

func (pd *ParamDecoder) Decode(req *http.Request) (string, bool)

Decode implements the AuthDecoder interface.

type QueryDecoder

type QueryDecoder struct {
	Key string
}

QueryDecoder decodes the query parameters.

func (*QueryDecoder) Decode

func (qd *QueryDecoder) Decode(req *http.Request) (string, bool)

Decode implements the AuthDecoder interface.

type RequestParser

type RequestParser interface {
	Parse(req *http.Request) (Authenticator, bool)
}

func NewRequestParser

func NewRequestParser(decodes ...AuthDecoder) RequestParser

NewRequestParser creates a new RequestParser with specified fields.

type ResponseWriter

type ResponseWriter interface {
	Write(http.ResponseWriter, Authenticator) error
}

type SessionDecoder

type SessionDecoder struct {
	SessionIDKey   string
	SessionStorage cache.Cache
}

SessionDecoder decodes the session information.

func (*SessionDecoder) Decode

func (sd *SessionDecoder) Decode(req *http.Request) (string, bool)

Decode implements the AuthDecoder interface.

Jump to

Keyboard shortcuts

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