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"
|
2020-02-05 04:18:02 +07:00
|
|
|
"github.com/authelia/authelia/internal/authorization"
|
2019-12-24 09:14:52 +07:00
|
|
|
"github.com/authelia/authelia/internal/middlewares"
|
2019-12-07 23:40:42 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
type ExtendedConfigurationBody struct {
|
|
|
|
AvailableMethods MethodList `json:"available_methods"`
|
2020-02-05 04:18:02 +07:00
|
|
|
|
|
|
|
// OneFactorDefaultPolicy is set if default policy is 'one_factor'
|
|
|
|
OneFactorDefaultPolicy bool `json:"one_factor_default_policy"`
|
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}
|
|
|
|
|
|
|
|
if ctx.Configuration.DuoAPI != nil {
|
|
|
|
body.AvailableMethods = append(body.AvailableMethods, authentication.Push)
|
|
|
|
}
|
|
|
|
|
2020-02-05 04:18:02 +07:00
|
|
|
defaultPolicy := authorization.PolicyToLevel(ctx.Configuration.AccessControl.DefaultPolicy)
|
|
|
|
body.OneFactorDefaultPolicy = defaultPolicy == authorization.OneFactor
|
|
|
|
ctx.Logger.Tracef("Default policy set to one factor: %v", body.OneFactorDefaultPolicy)
|
|
|
|
|
|
|
|
ctx.Logger.Tracef("Available methods are %s", body.AvailableMethods)
|
2019-12-07 23:40:42 +07:00
|
|
|
ctx.SetJSONBody(body)
|
|
|
|
}
|