Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BasicAuthHeader ¶
BasicAuthHeader creates a basic auth header.
func BasicAuthUserPass ¶
BasicAuthUserPass base64 encodes userid and password and returns the encoded string.: https://datatracker.ietf.org/doc/html/rfc2617#section-2 user-pass = userid ":" password userid = *<TEXT excluding ":"> password = *TEXT
func ParseBasicAuthHeader ¶
ParseBasicAuthHeader parses the basic authentication header and returns the username and password. It takes the authentication header string as input and returns the username, password, and a boolean indicating success. If the header is not in the correct format or decoding fails, it returns empty strings and false.
Types ¶
type Authorize ¶
type Authorize struct {
// Type is the type of authorization.
Type Type
// Credentials are the credentials associated with the authorization.
Credentials string
}
Authorize represents an authorization.
func ParseHTTPRequest ¶
ParseHTTPRequest parses the Authorization header from the provided HTTP request. If the header is empty, it returns nil and false.
func ParseHeader ¶
ParseHeader parses the authorization header and returns an Authorize 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 Authorize struct with the credentials and true. If the type is not recognized, it returns TypeUnknown with the original auth string and false.
func ParseWWWRequest ¶
ParseWWWRequest parses the WWW-Authenticate header from the provided HTTP request. If the header is empty, it returns nil and false. TODO: Implement the parsing logic based on https://tools.ietf.org/html/rfc7235#section-4.1
type Type ¶
type Type string
Type represents the type of authorization.
const ( // TypeAnonymous represents an anonymous authorization. TypeAnonymous Type = "anonymous" // TypeBasic represents a basic authorization. TypeBasic Type = "basic" // TypeBearer represents a bearer authorization. TypeBearer Type = "bearer" // TypeDigest represents a digest authorization. TypeDigest Type = "digest" // TypeUnknown represents an unknown authorization. TypeUnknown Type = "unknown" )