Documentation
¶
Index ¶
- func GetSessionFromContext(ctx context.Context) (behemoth.Session, bool)
- func InitDatabase[T behemoth.User](cfg *behemoth.DatabaseConfig[T], sessionFactory behemoth.SessionFactory) (behemoth.Database[T], error)
- type Behemoth
- type DefaultJWTClaims
- type JWTService
- type OAuthAuth
- type PasswordAuth
- type PasswordCredentials
- type SessionManager
- func (sm *SessionManager) CreateSession() (behemoth.Session, error)
- func (sm *SessionManager) DeleteSession(sessionID string) error
- func (sm *SessionManager) Expiry() time.Duration
- func (sm *SessionManager) GetSession(sessionID string) (behemoth.Session, error)
- func (sm *SessionManager) Middleware(next http.Handler) http.Handler
- func (sm *SessionManager) UpdateSession(session behemoth.Session) (behemoth.Session, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSessionFromContext ¶
GetSessionFromContext extracts a session from a given context if it was set by the SessionManager Middleware
func InitDatabase ¶
func InitDatabase[T behemoth.User]( cfg *behemoth.DatabaseConfig[T], sessionFactory behemoth.SessionFactory, ) (behemoth.Database[T], error)
Types ¶
type Behemoth ¶
type Behemoth[T behemoth.User] struct { DB behemoth.Database[T] Password *PasswordAuth[T] OAuth *OAuthAuth[T] JWT *JWTService Session *SessionManager UseSessions bool }
type DefaultJWTClaims ¶
type DefaultJWTClaims struct {
ID string `json:"id"`
jwt.RegisteredClaims
}
type JWTService ¶
type JWTService struct {
// contains filtered or unexported fields
}
func NewJWTService ¶
func NewJWTService(cfg behemoth.JWTConfig) *JWTService
func (*JWTService) GenerateToken ¶
func (j *JWTService) GenerateToken(user behemoth.User) (string, error)
func (*JWTService) ValidateToken ¶
func (j *JWTService) ValidateToken(tokenStr string) (jwt.Claims, error)
type OAuthAuth ¶
OAuthAuth manages OAuth-based authentication for multiple providers. It supports generic user types and handles authentication flows for providers like Google and Facebook.
func NewOAuthAuth ¶
func (*OAuthAuth[T]) Authenticate ¶
Authenticate performs OAuth authentication for the specified provider using the given credentials. It exchanges the OAuth code for a token, fetches user info, and saves the user to the database. Returns the authenticated user or an error if authentication fails.
type PasswordAuth ¶
func NewPasswordAuth ¶
func NewPasswordAuth[T behemoth.User](cfg behemoth.PasswordConfig, jwtSvc *JWTService, useDefaultUser bool, user behemoth.User, db behemoth.Database[T], ) *PasswordAuth[T]
func (*PasswordAuth[T]) Authenticate ¶
func (p *PasswordAuth[T]) Authenticate(credentials any) (behemoth.User, error)
type PasswordCredentials ¶
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager handles session creation, retrieval, and deletion.
func NewSessionManager ¶
func NewSessionManager( store behemoth.SessionStore, expiry time.Duration, cookieName string, factory behemoth.SessionFactory, ) *SessionManager
NewSessionManager creates a new SessionManager with the given database and configuration.
func (*SessionManager) CreateSession ¶
func (sm *SessionManager) CreateSession() (behemoth.Session, error)
CreateSession creates a new session with a unique ID and stores it in the backend.
func (*SessionManager) DeleteSession ¶
func (sm *SessionManager) DeleteSession(sessionID string) error
DeleteSession removes a session by ID from the backend.
func (*SessionManager) Expiry ¶
func (sm *SessionManager) Expiry() time.Duration
func (*SessionManager) GetSession ¶
func (sm *SessionManager) GetSession(sessionID string) (behemoth.Session, error)
GetSession retrieves a session by ID, returning an error if not found or expired.
func (*SessionManager) Middleware ¶
func (sm *SessionManager) Middleware(next http.Handler) http.Handler
Middleware checks for a session in incoming requests and adds it to the context.