Documentation ¶
Index ¶
- Variables
- func InvalidateSessions(db *gorm.DB, authID uint, authKey string) error
- func Login(db *gorm.DB, model IdentifiedAuthModel, c echo.Context, isSessionCookie bool) error
- func LoginRequired(f func(echo.Context) error) echo.HandlerFunc
- func Logout(db *gorm.DB, c echo.Context) error
- func Panic() echo.MiddlewareFunc
- func RegisterAuthProvider(getProviderInformation func() (string, func(uint) any))
- func Security(config *SecurityConfig) echo.MiddlewareFunc
- func Session(db *gorm.DB, config *SessionConfig) echo.MiddlewareFunc
- type AllowedHost
- type IdentifiedAuthModel
- type SecurityConfig
- type SessionConfig
- type SessionContext
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func InvalidateSessions ¶
InvalidateSessions Helper method to invalidate all sessions of a user
func Login ¶
func Login(db *gorm.DB, model IdentifiedAuthModel, c echo.Context, isSessionCookie bool) error
Login This method is used to log a user in. auth.Authenticate has to be called before. A cookie is set if the user can be logged in. Parameter user: Can be retrieved by auth.Authenticate. Parameter c: Pointer to the current context. Must implement middleware.SessionContext Parameter config: Refer to SessionConfig. Parameter isSessionCookie: Sets a session cookie if true, else a persistent cookie will be set.
func LoginRequired ¶
func LoginRequired(f func(echo.Context) error) echo.HandlerFunc
LoginRequired Helper function to mark endpoint as login only. Requires Session as a middleware. Returns ErrSessionMisconfigured if middleware.SessionContext is not present in Context.
func Logout ¶
Logout Helper method to logout and therefore invalidating a user's session. If the user isn't logged in, nil is returned
func RegisterAuthProvider ¶ added in v0.3.0
RegisterAuthProvider is used to register a new auth provider besides the already existing ones. The authIdentifier must be unique and is used to retrieve the correct UserModel with getUserModel which should return its own user struct
func Security ¶
func Security(config *SecurityConfig) echo.MiddlewareFunc
func Session ¶
func Session(db *gorm.DB, config *SessionConfig) echo.MiddlewareFunc
Session Use as middleware. Requires CustomContext to be set with a corresponding struct that embeds SessionContext or has a field named SessionContext. If SessionContext is not found, the middleware is skipped.
Types ¶
type AllowedHost ¶
type IdentifiedAuthModel ¶ added in v0.3.0
type SecurityConfig ¶
type SecurityConfig struct { AllowedHosts []AllowedHost UseForwardedProtoHeader bool }
type SessionConfig ¶
type SessionConfig struct { CookieName string CookieAge *time.Duration Secure *bool CookiePath string DisableLogging bool }
SessionConfig Set the parameters for the Session. Parameter CookieName defaults to "session_id". Parameter CookieAge defaults to 30 * time.Minute. Parameter Secure defaults to true. If set, the cookie can only be sent through an HTTPS connection. Parameter CookiePath defaults to "". Can be used to restrict the path the cookie can be sent to. Parameter DisableLogging defaults to false. If set, no debug logs are sent. Error logs are still sent.
func (*SessionConfig) FixSessionConfig ¶
func (config *SessionConfig) FixSessionConfig()
type SessionContext ¶
type SessionContext interface { GetUser() any GetSessionID() *string IsAuthenticated() bool GetSessionConfig() *SessionConfig // contains filtered or unexported methods }
func GetSessionContext ¶
func GetSessionContext(c echo.Context) (SessionContext, error)
GetSessionContext returns a SessionContext from a Context