2019-12-07 23:40:42 +07:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2019-12-24 09:14:52 +07:00
|
|
|
"github.com/authelia/authelia/internal/authentication"
|
|
|
|
"github.com/authelia/authelia/internal/middlewares"
|
2019-12-07 23:40:42 +07:00
|
|
|
)
|
|
|
|
|
2020-05-02 12:06:39 +07:00
|
|
|
// ExtendedConfigurationBody the content returned by extended configuration endpoint.
|
2019-12-07 23:40:42 +07:00
|
|
|
type ExtendedConfigurationBody struct {
|
2020-04-04 06:11:33 +07:00
|
|
|
AvailableMethods MethodList `json:"available_methods"`
|
2020-06-19 17:50:21 +07:00
|
|
|
DisplayName string `json:"display_name"`
|
2020-05-02 12:06:39 +07:00
|
|
|
SecondFactorEnabled bool `json:"second_factor_enabled"` // whether second factor is enabled or not.
|
2020-04-04 06:11:33 +07:00
|
|
|
TOTPPeriod int `json:"totp_period"`
|
2019-12-07 23:40:42 +07:00
|
|
|
}
|
|
|
|
|
2020-01-06 06:03:16 +07:00
|
|
|
// ExtendedConfigurationGet get the extended configuration accessible to authenticated users.
|
2019-12-07 23:40:42 +07:00
|
|
|
func ExtendedConfigurationGet(ctx *middlewares.AutheliaCtx) {
|
|
|
|
body := ExtendedConfigurationBody{}
|
|
|
|
body.AvailableMethods = MethodList{authentication.TOTP, authentication.U2F}
|
2020-06-19 17:50:21 +07:00
|
|
|
body.DisplayName = ctx.GetSession().DisplayName
|
2020-03-25 08:48:20 +07:00
|
|
|
body.TOTPPeriod = ctx.Configuration.TOTP.Period
|
2019-12-07 23:40:42 +07:00
|
|
|
|
|
|
|
if ctx.Configuration.DuoAPI != nil {
|
|
|
|
body.AvailableMethods = append(body.AvailableMethods, authentication.Push)
|
|
|
|
}
|
|
|
|
|
2020-03-06 07:31:09 +07:00
|
|
|
body.SecondFactorEnabled = ctx.Providers.Authorizer.IsSecondFactorEnabled()
|
|
|
|
ctx.Logger.Tracef("Second factor enabled: %v", body.SecondFactorEnabled)
|
2020-02-05 04:18:02 +07:00
|
|
|
|
|
|
|
ctx.Logger.Tracef("Available methods are %s", body.AvailableMethods)
|
2020-04-22 10:33:14 +07:00
|
|
|
ctx.SetJSONBody(body) //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
|
2019-12-07 23:40:42 +07:00
|
|
|
}
|