Documentation
¶
Index ¶
- func WithSessionContext(r *http.Request) *http.Request
- type JWTGuard
- func (g *JWTGuard) Attempt(w http.ResponseWriter, r *http.Request, credentials map[string]interface{}, ...) (bool, error)
- func (g *JWTGuard) Check(r *http.Request) bool
- func (g *JWTGuard) GenerateRefreshToken(user auth.Authenticatable) (string, error)
- func (g *JWTGuard) GenerateToken(user auth.Authenticatable, claims ...map[string]interface{}) (string, error)
- func (g *JWTGuard) ID(r *http.Request) interface{}
- func (g *JWTGuard) Login(w http.ResponseWriter, r *http.Request, user auth.Authenticatable, ...) error
- func (g *JWTGuard) LoginByID(w http.ResponseWriter, r *http.Request, id interface{}, remember ...bool) error
- func (g *JWTGuard) Logout(w http.ResponseWriter, r *http.Request) error
- func (g *JWTGuard) RefreshToken(refreshToken string) (string, error)
- func (g *JWTGuard) SetProvider(provider auth.UserProvider)
- func (g *JWTGuard) StopCleanup()
- func (g *JWTGuard) User(r *http.Request) auth.Authenticatable
- func (g *JWTGuard) ValidateToken(token string) (*auth.Claims, error)
- type SessionGuard
- func (g *SessionGuard) Attempt(w http.ResponseWriter, r *http.Request, credentials map[string]interface{}, ...) (bool, error)
- func (g *SessionGuard) Check(r *http.Request) bool
- func (g *SessionGuard) ID(r *http.Request) interface{}
- func (g *SessionGuard) Login(w http.ResponseWriter, r *http.Request, user auth.Authenticatable, ...) error
- func (g *SessionGuard) LoginByID(w http.ResponseWriter, r *http.Request, id interface{}, remember ...bool) error
- func (g *SessionGuard) Logout(w http.ResponseWriter, r *http.Request) error
- func (g *SessionGuard) SetProvider(provider auth.UserProvider)
- func (g *SessionGuard) User(r *http.Request) auth.Authenticatable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithSessionContext ¶ added in v0.9.3
WithSessionContext returns a new request with a session cache attached to its context. Call this from middleware to enable per-request session caching that is automatically cleaned up when the request completes.
Types ¶
type JWTGuard ¶
type JWTGuard struct {
// contains filtered or unexported fields
}
JWTGuard implements JWT-based authentication for APIs
func NewJWTGuard ¶
func NewJWTGuard(provider auth.UserProvider, config auth.JWTConfig, ctx ...context.Context) *JWTGuard
NewJWTGuard creates a new JWT guard. An optional context.Context can be passed to control the lifecycle of the background cache cleanup goroutine. When the context is cancelled, the cleanup goroutine stops automatically. If no context is provided, call StopCleanup() to stop the goroutine manually.
func (*JWTGuard) Attempt ¶
func (g *JWTGuard) Attempt(w http.ResponseWriter, r *http.Request, credentials map[string]interface{}, remember ...bool) (bool, error)
Attempt validates credentials and generates JWT if valid
func (*JWTGuard) GenerateRefreshToken ¶
func (g *JWTGuard) GenerateRefreshToken(user auth.Authenticatable) (string, error)
GenerateRefreshToken generates a refresh token
func (*JWTGuard) GenerateToken ¶
func (g *JWTGuard) GenerateToken(user auth.Authenticatable, claims ...map[string]interface{}) (string, error)
GenerateToken generates a JWT token for a user
func (*JWTGuard) Login ¶
func (g *JWTGuard) Login(w http.ResponseWriter, r *http.Request, user auth.Authenticatable, remember ...bool) error
Login generates a JWT token for the user
func (*JWTGuard) LoginByID ¶
func (g *JWTGuard) LoginByID(w http.ResponseWriter, r *http.Request, id interface{}, remember ...bool) error
LoginByID logs in a user by ID and generates JWT
func (*JWTGuard) RefreshToken ¶
RefreshToken refreshes an access token using refresh token
func (*JWTGuard) SetProvider ¶
func (g *JWTGuard) SetProvider(provider auth.UserProvider)
SetProvider sets the user provider
func (*JWTGuard) StopCleanup ¶ added in v0.9.3
func (g *JWTGuard) StopCleanup()
StopCleanup stops the background cache cleanup goroutine.
type SessionGuard ¶
type SessionGuard struct {
// contains filtered or unexported fields
}
SessionGuard implements session-based authentication
func NewSessionGuard ¶
func NewSessionGuard(provider auth.UserProvider, config auth.SessionConfig) (*SessionGuard, error)
NewSessionGuard creates a new session guard
func (*SessionGuard) Attempt ¶
func (g *SessionGuard) Attempt(w http.ResponseWriter, r *http.Request, credentials map[string]interface{}, remember ...bool) (bool, error)
Attempt attempts to log in with credentials
func (*SessionGuard) Check ¶
func (g *SessionGuard) Check(r *http.Request) bool
Check if user is authenticated
func (*SessionGuard) ID ¶
func (g *SessionGuard) ID(r *http.Request) interface{}
ID returns the authenticated user ID
func (*SessionGuard) Login ¶
func (g *SessionGuard) Login(w http.ResponseWriter, r *http.Request, user auth.Authenticatable, remember ...bool) error
Login logs in a user
func (*SessionGuard) LoginByID ¶
func (g *SessionGuard) LoginByID(w http.ResponseWriter, r *http.Request, id interface{}, remember ...bool) error
LoginByID logs in a user by ID
func (*SessionGuard) Logout ¶
func (g *SessionGuard) Logout(w http.ResponseWriter, r *http.Request) error
Logout logs out the user
func (*SessionGuard) SetProvider ¶
func (g *SessionGuard) SetProvider(provider auth.UserProvider)
SetProvider sets the user provider
func (*SessionGuard) User ¶
func (g *SessionGuard) User(r *http.Request) auth.Authenticatable
User returns the authenticated user