Documentation
¶
Overview ¶
Package auth is used for HTTP authentication
Index ¶
- Variables
- func NewBasicHandler(client *http.Client, clientID, host string, credsFn CredsFn, slog *slog.Logger) handler
- func NewBearerHandler(client *http.Client, clientID, host string, credsFn CredsFn, slog *slog.Logger) handler
- func NewJWTHubHandler(client *http.Client, clientID, host string, credsFn CredsFn, slog *slog.Logger) handler
- func ParseAuthHeaders(ahl []string) ([]challenge, error)
- type Auth
- type Cred
- type CredsFn
- type Opts
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyChallenge indicates an issue with the received challenge in the WWW-Authenticate header // // Deprecated: replace with [errs.ErrEmptyChallenge]. ErrEmptyChallenge = errs.ErrEmptyChallenge // ErrInvalidChallenge indicates an issue with the received challenge in the WWW-Authenticate header // // Deprecated: replace with [errs.ErrInvalidChallenge]. ErrInvalidChallenge = errs.ErrInvalidChallenge // ErrNoNewChallenge indicates a challenge update did not result in any change // // Deprecated: replace with [errs.ErrNoNewChallenge]. ErrNoNewChallenge = errs.ErrNoNewChallenge // ErrNotFound indicates no credentials found for basic auth // // Deprecated: replace with [errs.ErrNotFound]. ErrNotFound = errs.ErrNotFound // ErrNotImplemented returned when method has not been implemented yet // // Deprecated: replace with [errs.ErrNotImplemented]. ErrNotImplemented = errs.ErrNotImplemented // ErrParseFailure indicates the WWW-Authenticate header could not be parsed // // Deprecated: replace with [errs.ErrParseFailure]. ErrParseFailure = errs.ErrParsingFailed // // Deprecated: replace with [errs.ErrUnauthorized]. ErrUnauthorized = errs.ErrHTTPUnauthorized // ErrUnsupported indicates the request was unsupported // // Deprecated: replace with [errs.ErrUnsupported]. ErrUnsupported = errs.ErrUnsupported )
Functions ¶
func NewBasicHandler ¶
func NewBasicHandler(client *http.Client, clientID, host string, credsFn CredsFn, slog *slog.Logger) handler
NewBasicHandler creates a new BasicHandler
func NewBearerHandler ¶
func NewBearerHandler(client *http.Client, clientID, host string, credsFn CredsFn, slog *slog.Logger) handler
NewBearerHandler creates a new BearerHandler
func NewJWTHubHandler ¶ added in v0.7.2
func NewJWTHubHandler(client *http.Client, clientID, host string, credsFn CredsFn, slog *slog.Logger) handler
NewJWTHubHandler creates a new JWTHandler for Docker Hub.
func ParseAuthHeaders ¶
ParseAuthHeaders extracts the scheme and realm from WWW-Authenticate headers
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth is used to handle authentication requests.
func (*Auth) AddScope ¶
AddScope extends an existing auth with additional scopes. This is used to pre-populate scopes with the Docker convention rather than depend on the registry to respond with the correct http status and headers.
func (*Auth) HandleResponse ¶
HandleResponse parses the 401 response, extracting the WWW-Authenticate header and verifying the requirement is different from what was included in the last request
type Cred ¶
type Cred struct {
User, Password string // clear text username and password
Token string // refresh token only used for bearer auth
}
Cred is returned by the CredsFn. If Token is provided and auth method is bearer, it will attempt to use it as a refresh token. Else if user and password are provided, they are attempted with all auth methods. Else if neither are provided and auth method is bearer, an anonymous login is attempted.
func DefaultCredsFn ¶
DefaultCredsFn is used to return no credentials when auth is not configured with a CredsFn This avoids the need to check for nil pointers
type CredsFn ¶
CredsFn is passed to lookup credentials for a given hostname, response is a username and password or empty strings
type Opts ¶
type Opts func(*Auth)
Opts configures options for NewAuth
func WithClientID ¶
WithClientID uses a client ID with request headers
func WithDefaultHandlers ¶
func WithDefaultHandlers() Opts
WithDefaultHandlers includes a Basic and Bearer handler, this is automatically added with "WithHandler" is not called
func WithHTTPClient ¶
WithHTTPClient uses a specific http client with requests
func WithHandler ¶
WithHandler includes a handler for a specific auth type