Documentation
¶
Overview ¶
Package jwt provides JWT token generation and validation services.
Index ¶
- Variables
- func GenerateRandomToken(length int) (string, error)
- type Claims
- type Service
- func (s *Service) AccessTokenTTL() time.Duration
- func (s *Service) GenerateAccessToken(userID uuid.UUID, email string, isPlatformAdmin bool) (string, int, error)
- func (s *Service) GenerateTokenPair(userID uuid.UUID, email string, isPlatformAdmin bool) (*TokenPair, error)
- func (s *Service) RefreshTokenTTL() time.Duration
- func (s *Service) ValidateAccessToken(tokenString string) (*Claims, error)
- type TokenPair
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidToken = errors.New("invalid token") ErrExpiredToken = errors.New("token has expired") )
Functions ¶
func GenerateRandomToken ¶
GenerateRandomToken generates a cryptographically secure random token.
Types ¶
type Claims ¶
type Claims struct {
jwt.RegisteredClaims
UserID uuid.UUID `json:"user_id"`
Email string `json:"email"`
IsPlatformAdmin bool `json:"is_platform_admin,omitempty"`
}
Claims represents the JWT claims for access tokens.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles JWT token operations.
func NewService ¶
NewService creates a new JWT service.
func NewServiceWithIssuer ¶
func NewServiceWithIssuer(secret string, accessTTLSeconds, refreshTTLSeconds int, issuer string) *Service
NewServiceWithIssuer creates a new JWT service with a custom issuer.
func (*Service) AccessTokenTTL ¶
AccessTokenTTL returns the access token TTL.
func (*Service) GenerateAccessToken ¶
func (s *Service) GenerateAccessToken(userID uuid.UUID, email string, isPlatformAdmin bool) (string, int, error)
GenerateAccessToken generates only an access token (useful for token refresh).
func (*Service) GenerateTokenPair ¶
func (s *Service) GenerateTokenPair(userID uuid.UUID, email string, isPlatformAdmin bool) (*TokenPair, error)
GenerateTokenPair generates a new access and refresh token pair.
func (*Service) RefreshTokenTTL ¶
RefreshTokenTTL returns the refresh token TTL.
Click to show internal directories.
Click to hide internal directories.