token

package
v1.1.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ErrInvalidJWT = "Invalid JWT."
	ErrExpiredJWT = "Token has expired."
)

Variables

View Source
var (
	ErrJWT = errors.New("JWT error")
)

Functions

func EncodeJWT

func EncodeJWT(ctx context.Context, jwtSecret, userID string, expiresIn time.Duration, tokenType JWTType) (string, *apierror.APIError)

EncodeJWT encodes a new JWT for the given user ID, expiration, and token type.

func GenOpaqueToken

func GenOpaqueToken(ctx context.Context) (string, *apierror.APIError)

GenOpaqueToken generates a new opaque token.

func SanitizeJWT

func SanitizeJWT(tokenString string) string

SanitizeJWT sanitizes a given JWT for display.

Types

type JWTClaims

type JWTClaims struct {
	jwt.RegisteredClaims
	TokenType JWTType `json:"token_type"`
}

func DecodeJWT

func DecodeJWT(ctx context.Context, jwtSecret, tokenString string, expectedType JWTType) (*JWTClaims, *apierror.APIError)

DecodeJWT decodes a given JWT string into claims.

type JWTType

type JWTType string

JWTType represents the type of JWT token.

const (
	// JWTTypeAccess represents an access token.
	JWTTypeAccess JWTType = "access"
	// JWTTypePasswordReset represents a password reset token.
	JWTTypePasswordReset JWTType = "password_reset"
	// JWTTypeMagicLogin represents a magic login token sent in the "already registered" email.
	JWTTypeMagicLogin JWTType = "magic_login"
)

Jump to

Keyboard shortcuts

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