auth

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidChallenge indicates an issue with the received challenge in the WWW-Authenticate header
	ErrInvalidChallenge = errors.New("Invalid challenge header")
	// ErrNoNewChallenge indicates a challenge update did not result in any change
	ErrNoNewChallenge = errors.New("No new challenge")
	// ErrNotFound indicates no credentials found for basic auth
	ErrNotFound = errors.New("No credentials available for basic auth")
	// ErrNotImplemented returned when method has not been implemented yet
	ErrNotImplemented = errors.New("Not implemented")
	// ErrParseFailure indicates the WWW-Authenticate header could not be parsed
	ErrParseFailure = errors.New("Parse failure")
	// ErrUnauthorized request was not authorized
	ErrUnauthorized = errors.New("Unauthorized")
	// ErrUnsupported indicates the request was unsupported
	ErrUnsupported = errors.New("Unsupported")
)

Functions

func DefaultCredsFn

func DefaultCredsFn(h string) (string, string)

DefaultCredsFn is used to return no credentials when auth is not configured with a CredsFn This avoids the need to check for nil pointers

Types

type Auth

type Auth interface {
	HandleResponse(*http.Response) error
	UpdateRequest(*http.Request) error
}

Auth manages authorization requests/responses for http requests

func NewAuth

func NewAuth(opts ...Opts) Auth

NewAuth creates a new Auth

type BasicHandler

type BasicHandler struct {
	// contains filtered or unexported fields
}

BasicHandler supports Basic auth type requests

func (*BasicHandler) GenerateAuth

func (b *BasicHandler) GenerateAuth() (string, error)

GenerateAuth for BasicHandler generates base64 encoded user/pass for a host

func (*BasicHandler) ProcessChallenge

func (b *BasicHandler) ProcessChallenge(c Challenge) error

ProcessChallenge for BasicHandler is a noop

type BearerHandler

type BearerHandler struct {
	// contains filtered or unexported fields
}

BearerHandler supports Bearer auth type requests

func (*BearerHandler) GenerateAuth

func (b *BearerHandler) GenerateAuth() (string, error)

GenerateAuth for BasicHandler generates base64 encoded user/pass for a host

func (*BearerHandler) ProcessChallenge

func (b *BearerHandler) ProcessChallenge(c Challenge) error

ProcessChallenge for BasicHandler is a noop Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:samalba/my-app:pull,push"

type BearerToken

type BearerToken struct {
	Token        string    `json:"token"`
	AccessToken  string    `json:"access_token"`
	ExpiresIn    int       `json:"expires_in"`
	IssuedAt     time.Time `json:"issued_at"`
	RefreshToken string    `json:"refresh_token"`
	Scope        string    `json:"scope"`
}

BearerToken is the json response to the Bearer request

type Challenge

type Challenge struct {
	// contains filtered or unexported fields
}

Challenge is the extracted contents of the WWW-Authenticate header

func ParseAuthHeader

func ParseAuthHeader(ah string) ([]Challenge, error)

ParseAuthHeader parses a single header line for WWW-Authenticate Example values: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:samalba/my-app:pull,push" Basic realm="GitHub Package Registry"

func ParseAuthHeaders

func ParseAuthHeaders(ahl []string) ([]Challenge, error)

ParseAuthHeaders extracts the scheme and realm from WWW-Authenticate headers

type CredsFn

type CredsFn func(string) (string, string)

CredsFn is passed to lookup credentials for a given hostname, response is a username and password or empty strings

type Handler

type Handler interface {
	ProcessChallenge(Challenge) error
	GenerateAuth() (string, error)
}

Handler handles a challenge for a host to return an auth header

func NewBasicHandler

func NewBasicHandler(client *http.Client, host, user, pass string) Handler

NewBasicHandler creates a new BasicHandler

func NewBearerHandler

func NewBearerHandler(client *http.Client, host, user, pass string) Handler

NewBearerHandler creates a new BearerHandler

type HandlerBuild

type HandlerBuild func(client *http.Client, host, user, pass string) Handler

HandlerBuild is used to make a new handler for a specific authType and URL

type Opts

type Opts func(*auth)

Opts configures options for NewAuth

func WithCreds

func WithCreds(f CredsFn) Opts

WithCreds provides a user/pass lookup for a url

func WithDefaultHandlers

func WithDefaultHandlers() Opts

WithDefaultHandlers includes a Basic and Bearer handler, this is automatically added with "WithHandler" is not called

func WithHTTPClient

func WithHTTPClient(h *http.Client) Opts

WithHTTPClient uses a specific http client with requests

func WithHandler

func WithHandler(authType string, hb HandlerBuild) Opts

WithHandler includes a handler for a specific auth type

func WithLog

func WithLog(log *logrus.Logger) Opts

WithLog injects a logrus Logger

Jump to

Keyboard shortcuts

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