Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JwtAuth ¶
JwtAuth provides JWT token generation and verification functionality. It is parameterized by the claims type for type safety.
func NewJwtAuth ¶
NewJwtAuth creates a new JWT authenticator with the specified secret and options. The default signing method is HMAC-SHA256.
func (*JwtAuth[T]) GenerateToken ¶
GenerateToken creates a signed JWT token from the provided claims.
func (*JwtAuth[T]) ParseToken ¶
ParseToken parses and validates a signed JWT token, returning the claims. It handles both direct jwt.Claims types and custom structs, using JSON marshaling/unmarshaling for struct conversion when necessary.
type Option ¶
type Option func(*options)
Option is a functional option for configuring JWT authentication.
func WithSigningMethod ¶
func WithSigningMethod(method jwt.SigningMethod) Option
WithSigningMethod sets the JWT signing method for token generation and verification.
type RBACClaims ¶
type RBACClaims[T authorizer.UID] struct { jwt.RegisteredClaims UID T `json:"uid,omitempty"` Roles []string `json:"roles,omitempty"` }
func NewRBACClaims ¶
func NewRBACClaims[T authorizer.UID](uid T, subject string, roles []string, expiresAt time.Time) RBACClaims[T]
func (RBACClaims[T]) GetRoles ¶
func (r RBACClaims[T]) GetRoles() ([]string, error)
func (RBACClaims[T]) GetUID ¶
func (r RBACClaims[T]) GetUID() (T, error)