httpcontext

package
v0.0.0-...-b0bff92 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestModelUUID

func RequestModelUUID(req *http.Request) string

RequestModelUUID returns the model UUID associated with this request if there is one, or the empty string otherwise. No attempt is made to validate the model UUID; QueryModelHandler does this, and ImpliedModelHandler should always be supplied with a valid UUID.

Types

type AuthInfo

type AuthInfo struct {
	// Entity is the user/machine/unit/etc that has authenticated.
	Entity Entity

	// LastConnection returns the time of the last connection for
	// the authenticated entity. If it's the zero value, then the
	// entity has not previously logged in.
	LastConnection time.Time

	// Controller reports whether or not the authenticated
	// entity is a controller agent.
	Controller bool
}

AuthInfo is returned by Authenticator and RequestAuthInfo.

func RequestAuthInfo

func RequestAuthInfo(req *http.Request) (AuthInfo, bool)

RequestAuthInfo returns the AuthInfo associated with the request, if any, and a boolean indicating whether or not the request was authenticated.

type Authenticator

type Authenticator interface {
	// Authenticate authenticates the given request, returning the
	// auth info.
	//
	// If the request does not contain any authentication details,
	// then an error satisfying errors.IsNotFound will be returned.
	Authenticate(req *http.Request) (AuthInfo, error)

	// AuthenticateLoginRequest authenticates a LoginRequest.
	//
	// TODO(axw) we shouldn't be using params types here.
	AuthenticateLoginRequest(
		ctx context.Context,
		serverHost string,
		modelUUID string,
		req params.LoginRequest,
	) (AuthInfo, error)
}

Authenticator provides an interface for authenticating a request.

TODO(axw) contract should include macaroon discharge error.

If this returns an error, the handler should return StatusUnauthorized.

type Authorizer

type Authorizer interface {
	Authorize(AuthInfo) error
}

Authorizer is a function type for authorizing a request.

If this returns an error, the handler should return StatusForbidden.

type AuthorizerFunc

type AuthorizerFunc func(AuthInfo) error

AuthorizerFunc is a function type implementing Authorizer.

func (AuthorizerFunc) Authorize

func (f AuthorizerFunc) Authorize(info AuthInfo) error

Authorize is part of the Authorizer interface.

type BasicAuthHandler

type BasicAuthHandler struct {
	http.Handler

	// Authenticator is the Authenticator used for authenticating
	// the HTTP requests handled by this handler.
	Authenticator Authenticator

	// Authorizer, if non-nil, will be called with the auth info
	// returned by the Authenticator, to validate it for the route.
	Authorizer Authorizer
}

BasicAuthHandler is an http.Handler that authenticates requests that it handles with a specified Authenticator. The auth details can later be retrieved using the top-level RequestAuthInfo function in this package.

func (*BasicAuthHandler) ServeHTTP

func (h *BasicAuthHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP is part of the http.Handler interface.

type Entity

type Entity interface {
	Tag() names.Tag
}

Entity represents a user, machine, or unit that might be authenticated.

type ImpliedModelHandler

type ImpliedModelHandler struct {
	http.Handler
	ModelUUID string
}

ImpliedModelHandler is an http.Handler that associates requests that it handles with a specified model UUID. The model UUID can then be extracted using the RequestModel function in this package.

func (*ImpliedModelHandler) ServeHTTP

func (h *ImpliedModelHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP is part of the http.Handler interface.

type LocalMacaroonAuthenticator

type LocalMacaroonAuthenticator interface {
	Authenticator

	// CreateLocalLoginMacaroon creates a macaroon that may be
	// provided to a user as proof that they have logged in with
	// a valid username and password. This macaroon may then be
	// used to obtain a discharge macaroon so that the user can
	// log in without presenting their password for a set amount
	// of time.
	CreateLocalLoginMacaroon(context.Context, names.UserTag, bakery.Version) (*macaroon.Macaroon, error)
}

LocalMacaroonAuthenticator extends Authenticator with a method of creating a local login macaroon. The authenticator is expected to honour the resulting macaroon.

type QueryModelHandler

type QueryModelHandler struct {
	http.Handler
	Query string
}

QueryModelHandler is an http.Handler that associates requests that it handles with a model UUID extracted from a specified query parameter. The model UUID can then be extracted using the RequestModel function in this package.

func (*QueryModelHandler) ServeHTTP

func (h *QueryModelHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP is part of the http.Handler interface.

Jump to

Keyboard shortcuts

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