gak_jwt

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrJWTGenerationFailed = errors.New("failed to generate JWT")
	ErrJWTValidationFailed = errors.New("failed to validate JWT")
	ErrInvalidJWTSecret    = errors.New("invalid JWT secret")
	ErrInvalidSession      = errors.New("invalid session")
	ErrInvalidSID          = errors.New("invalid session ID")
)

Functions

func Authenticator

func Authenticator(opts *types.AuthOptions) func(ctx *gin.Context) (any, error)

Authenticator validates login credentials Called when: User attempts to login - validates email/password combination

func Authorizator

func Authorizator(data any, ctx *gin.Context) bool

Authorizator determines if authenticated user has access to resource Called when: Access to protected endpoint is requested - checks user permissions

func IdentityHandler

func IdentityHandler(opts *types.AuthOptions) func(ctx *gin.Context) any

IdentityHandler retrieves user identity from JWT claims Called when: JWT token is validated - reconstructs user from token claims

func PayloadFunc

func PayloadFunc(data any) jwt.MapClaims

PayloadFunc extracts user information into JWT claims Called when: User successfully logs in - creates JWT payload from user data

func Unauthorized

func Unauthorized(ctx *gin.Context, code int, message string)

Unauthorized handles cases where authentication/authorization fails Called when: JWT token is invalid, expired, or user lacks permissions

Types

type JWTExchangeService

type JWTExchangeService struct {
	// contains filtered or unexported fields
}

func NewJWTExchangeService

func NewJWTExchangeService(jwtSecret string, sessionService types.SessionService, jwtExpiry time.Duration) *JWTExchangeService

func (*JWTExchangeService) ExchangeSessionForJWT

func (exchangeService *JWTExchangeService) ExchangeSessionForJWT(sid string) (string, error)

func (*JWTExchangeService) RefreshSessionJWT

func (exchangeService *JWTExchangeService) RefreshSessionJWT(sid string) (string, error)

type JWTMiddleware

type JWTMiddleware struct {
	*jwt.GinJWTMiddleware
}

func NewJWTMiddleware

func NewJWTMiddleware(opts *JWTOptions) (*JWTMiddleware, error)

func (*JWTMiddleware) LoginHandler

func (j *JWTMiddleware) LoginHandler() gin.HandlerFunc

func (*JWTMiddleware) LogoutHandler

func (j *JWTMiddleware) LogoutHandler() gin.HandlerFunc

func (*JWTMiddleware) MiddlewareFunc

func (j *JWTMiddleware) MiddlewareFunc() gin.HandlerFunc

func (*JWTMiddleware) RefreshHandler

func (j *JWTMiddleware) RefreshHandler() gin.HandlerFunc

type JWTOptions

type JWTOptions struct {
	Realm           string
	Key             []byte
	Timeout         time.Duration
	MaxRefresh      time.Duration
	IdentityKey     string
	FindUserByEmail types.FindUserByEmailFunc
	FindUserByID    types.FindUserByIDFunc
	SessionSecure   bool
	SessionDomain   string
	SessionSameSite string
}

Jump to

Keyboard shortcuts

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