2019-04-25 04:52:08 +07:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2022-04-04 06:58:01 +07:00
|
|
|
"io"
|
|
|
|
|
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
|
|
|
|
|
2021-12-01 19:11:29 +07:00
|
|
|
// configurationBody the content returned by the configuration endpoint.
|
|
|
|
type configurationBody struct {
|
2022-03-03 18:20:43 +07:00
|
|
|
AvailableMethods MethodList `json:"available_methods"`
|
2021-12-01 10:32:58 +07:00
|
|
|
}
|
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2022-03-03 18:20:43 +07:00
|
|
|
// signWebauthnRequestBody model of the request body of Webauthn authentication endpoint.
|
|
|
|
type signWebauthnRequestBody struct {
|
|
|
|
TargetURL string `json:"targetURL"`
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
type signDuoRequestBody struct {
|
|
|
|
TargetURL string `json:"targetURL"`
|
2021-12-01 10:32:58 +07:00
|
|
|
Passcode string `json:"passcode"`
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
2021-12-01 19:11:29 +07:00
|
|
|
// preferred2FAMethodBody the selected 2FA method.
|
|
|
|
type preferred2FAMethodBody struct {
|
|
|
|
Method string `json:"method" valid:"required"`
|
|
|
|
}
|
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2021-12-01 10:32:58 +07:00
|
|
|
// DuoDeviceBody the selected Duo device and method.
|
|
|
|
type DuoDeviceBody struct {
|
|
|
|
Device string `json:"device" valid:"required"`
|
|
|
|
Method string `json:"method" valid:"required"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// DuoDevice represents Duo devices and methods.
|
|
|
|
type DuoDevice struct {
|
|
|
|
Device string `json:"device"`
|
|
|
|
DisplayName string `json:"display_name"`
|
|
|
|
Capabilities []string `json:"capabilities"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// DuoDevicesResponse represents all available user devices and methods as well as an optional enrollment url.
|
|
|
|
type DuoDevicesResponse struct {
|
|
|
|
Result string `json:"result" valid:"required"`
|
|
|
|
Devices []DuoDevice `json:"devices,omitempty"`
|
|
|
|
EnrollURL string `json:"enroll_url,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// DuoSignResponse represents a result of the preauth and or auth call with further optional info.
|
|
|
|
type DuoSignResponse struct {
|
|
|
|
Result string `json:"result" valid:"required"`
|
|
|
|
Devices []DuoDevice `json:"devices,omitempty"`
|
|
|
|
Redirect string `json:"redirect,omitempty"`
|
|
|
|
EnrollURL string `json:"enroll_url,omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-04-25 04:52:08 +07:00
|
|
|
// 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"`
|
|
|
|
}
|
2022-04-03 05:32:57 +07:00
|
|
|
|
|
|
|
// PassworPolicyBody represents the response sent by the password reset step 2.
|
|
|
|
type PassworPolicyBody struct {
|
|
|
|
Mode string `json:"mode"`
|
|
|
|
MinLength int `json:"min_length"`
|
|
|
|
MaxLength int `json:"max_length"`
|
|
|
|
RequireUppercase bool `json:"require_uppercase"`
|
|
|
|
RequireLowercase bool `json:"require_lowercase"`
|
|
|
|
RequireNumber bool `json:"require_number"`
|
|
|
|
RequireSpecial bool `json:"require_special"`
|
|
|
|
}
|
2022-04-04 06:58:01 +07:00
|
|
|
|
|
|
|
type responseWriter interface {
|
|
|
|
SetStatusCode(statusCode int)
|
|
|
|
SetBodyString(body string)
|
|
|
|
SetBody(body []byte)
|
|
|
|
SetContentType(contentType string)
|
|
|
|
SetContentTypeBytes(contentType []byte)
|
|
|
|
SetBodyStream(bodyStream io.Reader, bodySize int)
|
|
|
|
}
|