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