utilities

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractExp

func ExtractExp(token string) int64

ExtractExp returns the exp (expiration) claim of a JWT as a unix timestamp, without full signature validation (the caller has already validated the token via ValidateToken). Returns 0 if the token is malformed or the claim is missing — callers should treat 0 as "unknown" and fall back to a conservative default.

Used by Epic 56 to size the soft-unlock durable row's TTL to the JWT's actual remaining lifetime, rather than a hardcoded ceiling.

func ExtractJTI

func ExtractJTI(token string) string

ExtractJTI extracts the jti (JWT ID) claim from a JWT token without full validation (validation is already done by ValidateToken). Returns empty string if extraction fails.

func ExtractToken

func ExtractToken(c *gin.Context, config ...TokenExtractorConfig) string

ExtractToken extracts the authentication token from the request

func IsAPIKey

func IsAPIKey(token, prefix string) bool

IsAPIKey checks if a token is an API key based on its prefix

Types

type TokenExtractorConfig

type TokenExtractorConfig struct {
	// HeaderName is the name of the header containing the authentication token
	HeaderName string

	// TokenType is the type of token (e.g., "Bearer")
	TokenType string

	// QueryParamName is the name of the query parameter containing the authentication token
	QueryParamName string

	// CookieName is the name of the cookie containing the authentication token
	CookieName string
}

TokenExtractorConfig defines configuration for token extraction

func DefaultTokenExtractorConfig

func DefaultTokenExtractorConfig() TokenExtractorConfig

DefaultTokenExtractorConfig returns the default token extraction configuration

Jump to

Keyboard shortcuts

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