2022-11-19 05:48:47 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
2022-12-31 07:48:43 +00:00
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
|
2022-11-19 05:48:47 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/authentication"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Require1FA requires the user to have authenticated with at least one-factor authentication (i.e. password).
|
|
|
|
func Require1FA(next RequestHandler) RequestHandler {
|
|
|
|
return func(ctx *AutheliaCtx) {
|
|
|
|
if ctx.GetSession().AuthenticationLevel < authentication.OneFactor {
|
|
|
|
ctx.ReplyForbidden()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
next(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Require2FA requires the user to have authenticated with two-factor authentication.
|
|
|
|
func Require2FA(next RequestHandler) RequestHandler {
|
|
|
|
return func(ctx *AutheliaCtx) {
|
|
|
|
if ctx.GetSession().AuthenticationLevel < authentication.TwoFactor {
|
|
|
|
ctx.ReplyForbidden()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
next(ctx)
|
|
|
|
}
|
|
|
|
}
|
2022-12-31 07:48:43 +00:00
|
|
|
|
|
|
|
// Require2FAWithAPIResponse requires the user to have authenticated with two-factor authentication.
|
|
|
|
func Require2FAWithAPIResponse(next RequestHandler) RequestHandler {
|
|
|
|
return func(ctx *AutheliaCtx) {
|
|
|
|
if ctx.GetSession().AuthenticationLevel < authentication.TwoFactor {
|
|
|
|
ctx.SetAuthenticationErrorJSON(fasthttp.StatusForbidden, "Authentication Required.", true, false)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
next(ctx)
|
|
|
|
}
|
|
|
|
}
|