2019-04-25 04:52:08 +07:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tstranex/u2f"
|
2020-04-05 19:37:21 +07:00
|
|
|
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/authentication"
|
2019-04-25 04:52:08 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
// MethodList is the list of available methods.
|
|
|
|
type MethodList = []string
|
|
|
|
|
|
|
|
type authorizationMatching int
|
|
|
|
|
2020-06-21 20:40:37 +07:00
|
|
|
// UserInfo is the model of user info and second factor preferences.
|
|
|
|
type UserInfo struct {
|
|
|
|
// The users display name.
|
|
|
|
DisplayName string `json:"display_name"`
|
|
|
|
|
2020-01-06 06:03:16 +07:00
|
|
|
// The preferred 2FA method.
|
2019-04-25 04:52:08 +07:00
|
|
|
Method string `json:"method" valid:"required"`
|
2019-12-07 18:18:22 +07:00
|
|
|
|
2020-04-21 04:03:38 +07:00
|
|
|
// True if a security key has been registered.
|
2019-12-07 18:18:22 +07:00
|
|
|
HasU2F bool `json:"has_u2f" valid:"required"`
|
|
|
|
|
2020-04-21 04:03:38 +07:00
|
|
|
// True if a TOTP device has been registered.
|
2019-12-07 18:18:22 +07:00
|
|
|
HasTOTP bool `json:"has_totp" valid:"required"`
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// signTOTPRequestBody model of the request body received by TOTP authentication endpoint.
|
|
|
|
type signTOTPRequestBody struct {
|
|
|
|
Token string `json:"token" valid:"required"`
|
|
|
|
TargetURL string `json:"targetURL"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// signU2FRequestBody model of the request body of U2F authentication endpoint.
|
|
|
|
type signU2FRequestBody struct {
|
|
|
|
SignResponse u2f.SignResponse `json:"signResponse"`
|
|
|
|
TargetURL string `json:"targetURL"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type signDuoRequestBody struct {
|
|
|
|
TargetURL string `json:"targetURL"`
|
|
|
|
}
|
|
|
|
|
2021-03-05 11:18:31 +07:00
|
|
|
// firstFactorRequestBody represents the JSON body received by the endpoint.
|
2019-04-25 04:52:08 +07:00
|
|
|
type firstFactorRequestBody struct {
|
2021-03-05 11:18:31 +07:00
|
|
|
Username string `json:"username" valid:"required"`
|
|
|
|
Password string `json:"password" valid:"required"`
|
|
|
|
TargetURL string `json:"targetURL"`
|
|
|
|
RequestMethod string `json:"requestMethod"`
|
|
|
|
KeepMeLoggedIn *bool `json:"keepMeLoggedIn"`
|
|
|
|
// KeepMeLoggedIn: Cannot require this field because of https://github.com/asaskevich/govalidator/pull/329
|
2019-04-25 04:52:08 +07:00
|
|
|
// TODO(c.michaud): add required validation once the above PR is merged.
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:15:38 +07:00
|
|
|
// checkURIWithinDomainRequestBody represents the JSON body received by the endpoint checking if an URI is within
|
|
|
|
// the configured domain.
|
|
|
|
type checkURIWithinDomainRequestBody struct {
|
|
|
|
URI string `json:"uri"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type checkURIWithinDomainResponseBody struct {
|
|
|
|
OK bool `json:"ok"`
|
|
|
|
}
|
|
|
|
|
2019-04-25 04:52:08 +07:00
|
|
|
// redirectResponse represent the response sent by the first factor endpoint
|
|
|
|
// when a redirection URL has been provided.
|
|
|
|
type redirectResponse struct {
|
|
|
|
Redirect string `json:"redirect"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TOTPKeyResponse is the model of response that is sent to the client up successful identity verification.
|
|
|
|
type TOTPKeyResponse struct {
|
|
|
|
Base32Secret string `json:"base32_secret"`
|
|
|
|
OTPAuthURL string `json:"otpauth_url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// StateResponse represents the response sent by the state endpoint.
|
|
|
|
type StateResponse struct {
|
|
|
|
Username string `json:"username"`
|
|
|
|
AuthenticationLevel authentication.Level `json:"authentication_level"`
|
|
|
|
DefaultRedirectionURL string `json:"default_redirection_url"`
|
|
|
|
}
|
|
|
|
|
2020-04-21 04:03:38 +07:00
|
|
|
// resetPasswordStep1RequestBody model of the reset password (step1) request body.
|
2019-04-25 04:52:08 +07:00
|
|
|
type resetPasswordStep1RequestBody struct {
|
|
|
|
Username string `json:"username"`
|
|
|
|
}
|
|
|
|
|
2020-04-21 04:03:38 +07:00
|
|
|
// resetPasswordStep2RequestBody model of the reset password (step2) request body.
|
2019-04-25 04:52:08 +07:00
|
|
|
type resetPasswordStep2RequestBody struct {
|
|
|
|
Password string `json:"password"`
|
|
|
|
}
|