Documentation ¶
Index ¶
Constants ¶
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 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.
type FormDecoder ¶
type ParamDecoder ¶
type ParamDecoder struct {
Key string
}
type QueryDecoder ¶
type QueryDecoder struct {
Key string
}
QueryDecoder decodes the query parameters.
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
}