auth

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleHttpAuthentication

func HandleHttpAuthentication(auth Authenticator, request *http.Request, writer http.ResponseWriter) bool

HandleHttpAuthentication handles authentication headers and responses. If it returns false, authenticaten has failed, an appropriate response was sent and the caller should immediately return. A true return value indicates that authentication has succeeded and the caller should proceed with handling the request.

Types

type Authenticator

type Authenticator interface {
	// Authenticate parses an Authorization header and tries to authenticate the request.
	// Returns true if the authentication succeeded, false otherwise.
	Authenticate(authorization string) bool
	// AddUser adds a new user to the list.
	// Implementations may interpret users and passwords differently.
	AddUser(user, password string)
	// RemoveUser removes a user from the list.
	// Implementations may interpret users differently.
	RemoveUser(user string)
	// GetLogin returns an authentication string that can be sent to a remote system.
	GetLogin(user string) string
	// GetAuthenticateRequest returns a realm or other response that can be sent with a WWW-Authenticate header.
	GetAuthenticateRequest() string
}

Authenticator represents any type that can authenticate users.

func NewAuthenticator

func NewAuthenticator(auth configuration.Authentication, credentials map[string]configuration.UserCredentials) Authenticator

NewAuthenticator creates an authentication service from a credential database and an authentication specification. The implementation depends on the algorithm.

If an invalid authentication type is specified, an authenticator that will always deny requests is returned. If an empty authentication type is specified, an authenticator that will accept all requests is returned.

Note: Empty whitelists allow no users at all!

type UserAuthenticator

type UserAuthenticator struct {
	Auth Authenticator
	User string
}

UserAuthenticator is an authenticator that is bound to a single user. It does not implement the Authenticator interface because it doesn't support the user argument.

func NewUserAuthenticator

func NewUserAuthenticator(cred configuration.Authentication, auth Authenticator) *UserAuthenticator

NewUserAuthenticator creates a new user authenticator from an Authentication configuration and and an authenticator. If the Authentication does not contain any users, nil is returned. If it contains more than one user, the first one is used.

func (*UserAuthenticator) GetLogin

func (auth *UserAuthenticator) GetLogin() string

Jump to

Keyboard shortcuts

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