guards

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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) *JWTGuard

NewJWTGuard creates a new JWT guard

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) Check

func (g *JWTGuard) Check(r *http.Request) bool

Check if user is authenticated via JWT

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) ID

func (g *JWTGuard) ID(r *http.Request) interface{}

ID returns the authenticated user ID from JWT

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) Logout

func (g *JWTGuard) Logout(w http.ResponseWriter, r *http.Request) error

Logout revokes the JWT token

func (*JWTGuard) RefreshToken

func (g *JWTGuard) RefreshToken(refreshToken string) (string, error)

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) User

User returns the authenticated user from JWT

func (*JWTGuard) ValidateToken

func (g *JWTGuard) ValidateToken(token string) (*auth.Claims, error)

ValidateToken validates a JWT token

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

User returns the authenticated user

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL