mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 21:09:11 +00:00
52 lines
1016 B
Go
52 lines
1016 B
Go
package ctx
|
|
|
|
import "github.com/labstack/echo/v4"
|
|
|
|
type AuthState string
|
|
|
|
const (
|
|
Visitor AuthState = "visitor"
|
|
Authenticated AuthState = "authenticated"
|
|
Expired AuthState = "expired"
|
|
|
|
PendingCredentials AuthState = "pending_credentials"
|
|
PendingAssertion AuthState = "pending_assertion"
|
|
)
|
|
|
|
func (s AuthState) String() string {
|
|
return string(s)
|
|
}
|
|
|
|
func GetAuthState(c echo.Context) AuthState {
|
|
vals := c.Request().Header.Values("Authorization")
|
|
if len(vals) == 0 {
|
|
return Visitor
|
|
}
|
|
s := AuthState(c.Request().Header.Get("Authorization"))
|
|
return s
|
|
}
|
|
|
|
func readSessionFromStore(c echo.Context, id string) (*session, error) {
|
|
sess, err := store.Get(c.Request(), id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return NewSessionFromValues(sess.Values), nil
|
|
}
|
|
|
|
func writeSessionToStore(
|
|
c echo.Context,
|
|
id string,
|
|
) error {
|
|
sess, err := store.Get(c.Request(), id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s := defaultSession(id, sess)
|
|
err = s.SaveHTTP(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|