2019-12-07 23:40:42 +07:00
|
|
|
package handlers
|
|
|
|
|
2020-06-21 20:40:37 +07:00
|
|
|
import (
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/authentication"
|
|
|
|
"github.com/authelia/authelia/v4/internal/middlewares"
|
2020-06-21 20:40:37 +07:00
|
|
|
)
|
2019-12-07 23:40:42 +07:00
|
|
|
|
2020-06-21 20:40:37 +07:00
|
|
|
// ConfigurationBody the content returned by the configuration endpoint.
|
2019-12-07 23:40:42 +07:00
|
|
|
type ConfigurationBody struct {
|
2020-06-21 20:40:37 +07:00
|
|
|
AvailableMethods MethodList `json:"available_methods"`
|
|
|
|
SecondFactorEnabled bool `json:"second_factor_enabled"` // whether second factor is enabled or not.
|
|
|
|
TOTPPeriod int `json:"totp_period"`
|
2019-12-07 23:40:42 +07:00
|
|
|
}
|
|
|
|
|
2020-06-21 20:40:37 +07:00
|
|
|
// ConfigurationGet get the configuration accessible to authenticated users.
|
2019-12-07 23:40:42 +07:00
|
|
|
func ConfigurationGet(ctx *middlewares.AutheliaCtx) {
|
2020-06-21 20:40:37 +07:00
|
|
|
body := ConfigurationBody{}
|
|
|
|
body.AvailableMethods = MethodList{authentication.TOTP, authentication.U2F}
|
|
|
|
body.TOTPPeriod = ctx.Configuration.TOTP.Period
|
|
|
|
|
|
|
|
if ctx.Configuration.DuoAPI != nil {
|
|
|
|
body.AvailableMethods = append(body.AvailableMethods, authentication.Push)
|
2019-12-07 23:40:42 +07:00
|
|
|
}
|
2020-06-21 20:40:37 +07:00
|
|
|
|
|
|
|
body.SecondFactorEnabled = ctx.Providers.Authorizer.IsSecondFactorEnabled()
|
2021-06-18 08:38:01 +07:00
|
|
|
|
2020-06-21 20:40:37 +07:00
|
|
|
ctx.Logger.Tracef("Second factor enabled: %v", body.SecondFactorEnabled)
|
|
|
|
|
|
|
|
ctx.Logger.Tracef("Available methods are %s", body.AvailableMethods)
|
2020-12-16 08:47:31 +07:00
|
|
|
|
|
|
|
err := ctx.SetJSONBody(body)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Logger.Errorf("Unable to set configuration response in body: %s", err)
|
|
|
|
}
|
2019-12-07 23:40:42 +07:00
|
|
|
}
|