middlewares

package
v4.34.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// UserValueKeyBaseURL is the User Value key where we store the Base URL.
	UserValueKeyBaseURL = []byte("base_url")
)

Functions

func AssetOverrideMiddleware added in v4.33.0

func AssetOverrideMiddleware(assetPath string, next fasthttp.RequestHandler) fasthttp.RequestHandler

AssetOverrideMiddleware allows overriding and serving of specific embedded assets from disk.

func LogRequestMiddleware

func LogRequestMiddleware(next fasthttp.RequestHandler) fasthttp.RequestHandler

LogRequestMiddleware logs the query that is being treated.

func NewRequestLogger

func NewRequestLogger(ctx *AutheliaCtx) *logrus.Entry

NewRequestLogger create a new request logger for the given request.

func StripPathMiddleware

func StripPathMiddleware(path string, next fasthttp.RequestHandler) fasthttp.RequestHandler

StripPathMiddleware strips the first level of a path.

Types

type AutheliaCtx

type AutheliaCtx struct {
	*fasthttp.RequestCtx

	Logger        *logrus.Entry
	Providers     Providers
	Configuration schema.Configuration

	Clock utils.Clock
}

AutheliaCtx contains all server variables related to Authelia.

func NewAutheliaCtx

func NewAutheliaCtx(ctx *fasthttp.RequestCtx, configuration schema.Configuration, providers Providers) (*AutheliaCtx, error)

NewAutheliaCtx instantiate an AutheliaCtx out of a RequestCtx.

func (AutheliaCtx) AcceptsMIME

func (ctx AutheliaCtx) AcceptsMIME(mime string) (acceptsMime bool)

AcceptsMIME takes a mime type and returns true if the request accepts that type or the wildcard type.

func (*AutheliaCtx) BasePath

func (ctx *AutheliaCtx) BasePath() (base string)

BasePath returns the base_url as per the path visited by the client.

func (*AutheliaCtx) Error

func (ctx *AutheliaCtx) Error(err error, message string)

Error reply with an error and display the stack trace in the logs.

func (*AutheliaCtx) ExternalRootURL

func (ctx *AutheliaCtx) ExternalRootURL() (string, error)

ExternalRootURL gets the X-Forwarded-Proto, X-Forwarded-Host headers and the BasePath and forms them into a URL.

func (*AutheliaCtx) GetOriginalURL

func (ctx *AutheliaCtx) GetOriginalURL() (*url.URL, error)

GetOriginalURL extract the URL from the request headers (X-Original-URL or X-Forwarded-* headers).

func (*AutheliaCtx) GetSession

func (ctx *AutheliaCtx) GetSession() session.UserSession

GetSession return the user session. Any update will be saved in cache.

func (AutheliaCtx) IsXHR

func (ctx AutheliaCtx) IsXHR() (xhr bool)

IsXHR returns true if the request is a XMLHttpRequest.

func (*AutheliaCtx) ParseBody

func (ctx *AutheliaCtx) ParseBody(value interface{}) error

ParseBody parse the request body into the type of value.

func (*AutheliaCtx) RemoteIP

func (ctx *AutheliaCtx) RemoteIP() net.IP

RemoteIP return the remote IP taking X-Forwarded-For header into account if provided.

func (*AutheliaCtx) ReplyBadRequest

func (ctx *AutheliaCtx) ReplyBadRequest()

ReplyBadRequest response sent when bad request has been sent.

func (*AutheliaCtx) ReplyError

func (ctx *AutheliaCtx) ReplyError(err error, message string)

ReplyError reply with an error but does not display any stack trace in the logs.

func (*AutheliaCtx) ReplyForbidden

func (ctx *AutheliaCtx) ReplyForbidden()

ReplyForbidden response sent when access is forbidden to user.

func (*AutheliaCtx) ReplyOK

func (ctx *AutheliaCtx) ReplyOK()

ReplyOK is a helper method to reply ok.

func (*AutheliaCtx) ReplyUnauthorized

func (ctx *AutheliaCtx) ReplyUnauthorized()

ReplyUnauthorized response sent when user is unauthorized.

func (*AutheliaCtx) SaveSession

func (ctx *AutheliaCtx) SaveSession(userSession session.UserSession) error

SaveSession save the content of the session.

func (*AutheliaCtx) SetJSONBody

func (ctx *AutheliaCtx) SetJSONBody(value interface{}) error

SetJSONBody Set json body.

func (*AutheliaCtx) SetJSONError added in v4.33.0

func (ctx *AutheliaCtx) SetJSONError(message string)

SetJSONError sets the body of the response to an JSON error KO message.

func (*AutheliaCtx) SpecialRedirect

func (ctx *AutheliaCtx) SpecialRedirect(uri string, statusCode int)

SpecialRedirect performs a redirect similar to fasthttp.RequestCtx except it allows statusCode 401 and includes body content in the form of a link to the location.

func (*AutheliaCtx) XForwardedHost

func (ctx *AutheliaCtx) XForwardedHost() (host []byte)

XForwardedHost return the content of the X-Forwarded-Host header.

func (*AutheliaCtx) XForwardedMethod

func (ctx *AutheliaCtx) XForwardedMethod() (method []byte)

XForwardedMethod return the content of the X-Forwarded-Method header.

func (*AutheliaCtx) XForwardedProto

func (ctx *AutheliaCtx) XForwardedProto() (proto []byte)

XForwardedProto return the content of the X-Forwarded-Proto header.

func (*AutheliaCtx) XForwardedURI

func (ctx *AutheliaCtx) XForwardedURI() (uri []byte)

XForwardedURI return the content of the X-Forwarded-URI header.

func (*AutheliaCtx) XOriginalURL

func (ctx *AutheliaCtx) XOriginalURL() []byte

XOriginalURL return the content of the X-Original-URL header.

type AutheliaHandlerFunc

type AutheliaHandlerFunc func(ctx *AutheliaCtx, rw http.ResponseWriter, r *http.Request)

AutheliaHandlerFunc is used with the NewHTTPToAutheliaHandlerAdaptor to encapsulate a func.

type ErrorResponse

type ErrorResponse struct {
	Status  string `json:"status"`
	Message string `json:"message"`
}

ErrorResponse model of an error response.

type IdentityVerificationFinishArgs

type IdentityVerificationFinishArgs struct {
	// The action claim that should be in the token to consider the action legitimate.
	ActionClaim string

	// The function for checking the user in the token is valid for the current action.
	IsTokenUserValidFunc func(ctx *AutheliaCtx, username string) bool
}

IdentityVerificationFinishArgs represent the arguments used to customize the finishing phase of the identity verification process.

type IdentityVerificationFinishBody

type IdentityVerificationFinishBody struct {
	Token string `json:"token"`
}

IdentityVerificationFinishBody type of the body received by the finish endpoint.

type IdentityVerificationStartArgs

type IdentityVerificationStartArgs struct {
	// Email template needs a subject, a title and the content of the button.
	MailTitle         string
	MailButtonContent string

	// The target endpoint where to redirect the user when verification process
	// is completed successfully.
	TargetEndpoint string

	// The action claim that will be stored in the JWT token.
	ActionClaim string

	// The function retrieving the identity to who the email will be sent.
	IdentityRetrieverFunc func(ctx *AutheliaCtx) (*session.Identity, error)

	// The function for checking the user in the token is valid for the current action.
	IsTokenUserValidFunc func(ctx *AutheliaCtx, username string) bool
}

IdentityVerificationStartArgs represent the arguments used to customize the starting phase of the identity verification process.

type Middleware

type Middleware = func(RequestHandler) RequestHandler

Middleware represent an Authelia middleware.

type OKResponse

type OKResponse struct {
	Status string      `json:"status"`
	Data   interface{} `json:"data,omitempty"`
}

OKResponse model of a status OK response.

type Providers

type Providers struct {
	Authorizer      *authorization.Authorizer
	SessionProvider *session.Provider
	Regulator       *regulation.Regulator
	OpenIDConnect   oidc.OpenIDConnectProvider
	NTP             *ntp.Provider
	UserProvider    authentication.UserProvider
	StorageProvider storage.Provider
	Notifier        notification.Notifier
	TOTP            totp.Provider
}

Providers contain all provider provided to Authelia.

type RequestHandler

type RequestHandler = func(*AutheliaCtx)

RequestHandler represents an Authelia request handler.

func CORSApplyAutomaticAllowAllPolicy added in v4.34.0

func CORSApplyAutomaticAllowAllPolicy(next RequestHandler) RequestHandler

CORSApplyAutomaticAllowAllPolicy applies a CORS policy that automatically grants all Origins as well as all Request Headers other than Cookie and *. It does not allow credentials, and has a max age of 100. Vary is applied to both Accept-Encoding and Origin. It grants the GET Request Method only.

func IdentityVerificationFinish

func IdentityVerificationFinish(args IdentityVerificationFinishArgs, next func(ctx *AutheliaCtx, username string)) RequestHandler

IdentityVerificationFinish the middleware for finishing the identity validation process.

func IdentityVerificationStart

func IdentityVerificationStart(args IdentityVerificationStartArgs, delayFunc TimingAttackDelayFunc) RequestHandler

IdentityVerificationStart the handler for initiating the identity validation process.

func NewHTTPToAutheliaHandlerAdaptor

func NewHTTPToAutheliaHandlerAdaptor(h AutheliaHandlerFunc) RequestHandler

NewHTTPToAutheliaHandlerAdaptor creates a new adaptor given the AutheliaHandlerFunc.

func RequireFirstFactor

func RequireFirstFactor(next RequestHandler) RequestHandler

RequireFirstFactor check if user has enough permissions to execute the next handler.

type RequestHandlerBridge

type RequestHandlerBridge = func(RequestHandler) fasthttp.RequestHandler

RequestHandlerBridge bridge a AutheliaCtx handle to a RequestHandler handler.

func AutheliaMiddleware

func AutheliaMiddleware(configuration schema.Configuration, providers Providers) RequestHandlerBridge

AutheliaMiddleware is wrapping the RequestCtx into an AutheliaCtx providing Authelia related objects.

type TimingAttackDelayFunc added in v4.33.2

type TimingAttackDelayFunc func(logger *logrus.Entry, requestTime time.Time, successful *bool)

TimingAttackDelayFunc describes a function for preventing timing attacks via a delay.

func TimingAttackDelay added in v4.33.2

func TimingAttackDelay(history int, minDelayMs float64, maxRandomMs int64, initialDelay time.Duration) TimingAttackDelayFunc

TimingAttackDelay creates a new standard timing delay func.

Jump to

Keyboard shortcuts

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