2019-04-24 21:52:08 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
2020-04-05 12:37:21 +00:00
|
|
|
jwt "github.com/dgrijalva/jwt-go"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
|
2019-12-24 02:14:52 +00:00
|
|
|
"github.com/authelia/authelia/internal/authentication"
|
|
|
|
"github.com/authelia/authelia/internal/authorization"
|
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
|
|
"github.com/authelia/authelia/internal/notification"
|
|
|
|
"github.com/authelia/authelia/internal/regulation"
|
|
|
|
"github.com/authelia/authelia/internal/session"
|
|
|
|
"github.com/authelia/authelia/internal/storage"
|
2020-01-17 22:48:48 +00:00
|
|
|
"github.com/authelia/authelia/internal/utils"
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// AutheliaCtx contains all server variables related to Authelia.
|
|
|
|
type AutheliaCtx struct {
|
|
|
|
*fasthttp.RequestCtx
|
|
|
|
|
|
|
|
Logger *logrus.Entry
|
|
|
|
Providers Providers
|
|
|
|
Configuration schema.Configuration
|
2020-01-17 22:48:48 +00:00
|
|
|
|
|
|
|
Clock utils.Clock
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Providers contain all provider provided to Authelia.
|
|
|
|
type Providers struct {
|
|
|
|
Authorizer *authorization.Authorizer
|
|
|
|
SessionProvider *session.Provider
|
|
|
|
Regulator *regulation.Regulator
|
|
|
|
|
|
|
|
UserProvider authentication.UserProvider
|
|
|
|
StorageProvider storage.Provider
|
|
|
|
Notifier notification.Notifier
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestHandler represents an Authelia request handler.
|
|
|
|
type RequestHandler = func(*AutheliaCtx)
|
|
|
|
|
|
|
|
// Middleware represent an Authelia middleware.
|
|
|
|
type Middleware = func(RequestHandler) RequestHandler
|
|
|
|
|
|
|
|
// IdentityVerificationStartArgs represent the arguments used to customize the starting phase
|
|
|
|
// of the identity verification process.
|
|
|
|
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
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// The action claim that will be stored in the JWT token.
|
2019-04-24 21:52:08 +00:00
|
|
|
ActionClaim string
|
|
|
|
|
|
|
|
// The function retrieving the identity to who the email will be sent.
|
|
|
|
IdentityRetrieverFunc func(ctx *AutheliaCtx) (*session.Identity, error)
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// The function for checking the user in the token is valid for the current action.
|
2019-04-24 21:52:08 +00:00
|
|
|
IsTokenUserValidFunc func(ctx *AutheliaCtx, username string) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// IdentityVerificationFinishArgs represent the arguments used to customize the finishing phase
|
|
|
|
// of the identity verification process.
|
|
|
|
type IdentityVerificationFinishArgs struct {
|
2020-05-02 05:06:39 +00:00
|
|
|
// The action claim that should be in the token to consider the action legitimate.
|
2019-04-24 21:52:08 +00:00
|
|
|
ActionClaim string
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// The function for checking the user in the token is valid for the current action.
|
2019-04-24 21:52:08 +00:00
|
|
|
IsTokenUserValidFunc func(ctx *AutheliaCtx, username string) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// IdentityVerificationClaim custom claim for specifying the action claim.
|
|
|
|
// The action can be to register a TOTP device, a U2F device or reset one's password.
|
|
|
|
type IdentityVerificationClaim struct {
|
|
|
|
jwt.StandardClaims
|
|
|
|
|
|
|
|
// The action this token has been crafted for.
|
|
|
|
Action string `json:"action"`
|
|
|
|
// The user this token has been crafted for.
|
|
|
|
Username string `json:"username"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IdentityVerificationFinishBody type of the body received by the finish endpoint.
|
|
|
|
type IdentityVerificationFinishBody struct {
|
|
|
|
Token string `json:"token"`
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// OKResponse model of a status OK response.
|
2019-04-24 21:52:08 +00:00
|
|
|
type OKResponse struct {
|
|
|
|
Status string `json:"status"`
|
2020-02-01 12:54:50 +00:00
|
|
|
Data interface{} `json:"data,omitempty"`
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// ErrorResponse model of an error response.
|
2019-04-24 21:52:08 +00:00
|
|
|
type ErrorResponse struct {
|
|
|
|
Status string `json:"status"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
}
|