challengehandlers

package
v0.0.0-...-6018a90 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBasicAuthNoUsernameError

func NewBasicAuthNoUsernameError() error

NewBasicAuthNoUsernameError returns an error for a basic challenge without a username

Types

type BasicAuthNoUsernameError

type BasicAuthNoUsernameError struct{}

BasicAuthNoUsernameError when basic authentication challenge handling was attempted but the required username was not provided from the command line options

func (*BasicAuthNoUsernameError) Error

func (e *BasicAuthNoUsernameError) Error() string

type BasicChallengeHandler

type BasicChallengeHandler struct {
	// Host is the server being authenticated to. Used only for displaying messages when prompting for username/password
	Host string

	// WebConsoleURL is an optional URL to a web interface where the user might go if they prefer login from the browser instead
	WebConsoleURL string

	// Reader is used to prompt for username/password. If nil, no prompting is done
	Reader io.Reader
	// Writer is used to output prompts. If nil, stdout is used
	Writer io.Writer

	// Username is the username to use when challenged. If empty, a `BasicAuthNoUsernameError` is returned
	// when handling the challenge.
	Username string
	// Password is the password to use when challenged. If empty, a prompt is issued to a non-nil Reader
	Password string
	// contains filtered or unexported fields
}

BasicChallengeHandler handles the "WWW-Authenticate: Basic" challenges. It implements the `ChallengeHandler` interface.

func NewBasicChallengeHandler

func NewBasicChallengeHandler(
	host, consoleURL string,
	reader io.Reader,
	writer io.Writer,
	passwordPrompter PasswordPrompter,
	username, password string,
) *BasicChallengeHandler

func (*BasicChallengeHandler) CanHandle

func (c *BasicChallengeHandler) CanHandle(headers http.Header) bool

func (*BasicChallengeHandler) CompleteChallenge

func (c *BasicChallengeHandler) CompleteChallenge(requestURL string, headers http.Header) error

func (*BasicChallengeHandler) HandleChallenge

func (c *BasicChallengeHandler) HandleChallenge(requestURL string, headers http.Header) (http.Header, bool, error)

HandleChallenge attempts to handle the "WWW-Authenticate: Basic" challenge. It may prompt for a password matching the username that should already be a part of the BasicChallengeHandler. The prompt is supposed to be called only once but this assertion is thread unsafe.

func (*BasicChallengeHandler) Release

func (c *BasicChallengeHandler) Release() error

type ChallengeHandler

type ChallengeHandler interface {
	// CanHandle returns true if the handler recognizes a challenge it thinks it can handle.
	CanHandle(headers http.Header) bool
	// HandleChallenge lets the handler attempt to handle a challenge.
	// It is only invoked if CanHandle() returned true for the given headers.
	// Returns response headers and true if the challenge is successfully handled.
	// Returns false if the challenge was not handled, and an optional error in error cases.
	HandleChallenge(requestURL string, headers http.Header) (http.Header, bool, error)
	// CompleteChallenge is invoked with the headers from a successful server response
	// received after having handled one or more challenges.
	// Returns an error if the handler does not consider the challenge/response interaction complete.
	CompleteChallenge(requestURL string, headers http.Header) error
	// Release gives the handler a chance to release any resources held during a challenge/response sequence.
	// It is always invoked, even in cases where no challenges were received or handled.
	Release() error
}

ChallengeHandler handles responses to WWW-Authenticate challenges.

func NewMultiHandler

func NewMultiHandler(handlers ...ChallengeHandler) ChallengeHandler

type MultiHandler

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

MultiHandler manages a series of authentication challenges it is single-use only, and not thread-safe

func (*MultiHandler) CanHandle

func (h *MultiHandler) CanHandle(headers http.Header) bool

func (*MultiHandler) CompleteChallenge

func (h *MultiHandler) CompleteChallenge(requestURL string, headers http.Header) error

func (*MultiHandler) HandleChallenge

func (h *MultiHandler) HandleChallenge(requestURL string, headers http.Header) (http.Header, bool, error)

func (*MultiHandler) Handlers

func (h *MultiHandler) Handlers() []ChallengeHandler

func (*MultiHandler) Release

func (h *MultiHandler) Release() error

type PasswordPrompter

type PasswordPrompter interface {
	PromptForPassword(r io.Reader, w io.Writer, format string, a ...interface{}) string
}

PasswordPrompter is an interface for requesting passwords in the form of a string

Jump to

Keyboard shortcuts

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