2024-10-11 16:47:52 -04:00
|
|
|
package ctx
|
|
|
|
|
|
|
|
|
|
import "github.com/labstack/echo/v4"
|
|
|
|
|
|
2024-10-11 19:03:14 -04:00
|
|
|
type AuthState string
|
2024-10-11 16:47:52 -04:00
|
|
|
|
|
|
|
|
const (
|
2024-10-11 19:03:14 -04:00
|
|
|
Visitor AuthState = "visitor"
|
|
|
|
|
Authenticated AuthState = "authenticated"
|
|
|
|
|
Expired AuthState = "expired"
|
|
|
|
|
|
|
|
|
|
PendingCredentials AuthState = "pending_credentials"
|
|
|
|
|
PendingAssertion AuthState = "pending_assertion"
|
2024-10-11 16:47:52 -04:00
|
|
|
)
|
|
|
|
|
|
2024-10-11 19:03:14 -04:00
|
|
|
func (s AuthState) String() string {
|
2024-10-11 16:47:52 -04:00
|
|
|
return string(s)
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-11 19:03:14 -04:00
|
|
|
func GetAuthState(c echo.Context) AuthState {
|
|
|
|
|
vals := c.Request().Header.Values("Authorization")
|
|
|
|
|
if len(vals) == 0 {
|
|
|
|
|
return Visitor
|
2024-10-11 16:47:52 -04:00
|
|
|
}
|
2024-10-11 19:03:14 -04:00
|
|
|
s := AuthState(c.Request().Header.Get("Authorization"))
|
|
|
|
|
return s
|
2024-10-11 16:47:52 -04:00
|
|
|
}
|