jwt

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Secret   utils.SensitiveString `koanf:"secret" env:"JWT_SECRET" json:"secret"`
	Issuer   string                `koanf:"issuer" env:"JWT_ISSUER" json:"issuer" default:"postgres-config"`
	Audience string                `koanf:"audience" env:"JWT_AUDIENCE" json:"audience" default:"postgrest"`
}

Config holds configuration for JWT generator

type JWTGenerator

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

JWTGenerator handles JWT token creation and validation

func NewJWTGenerator

func NewJWTGenerator(secret utils.SensitiveString, issuer, audience string) *JWTGenerator

NewJWTGenerator creates a new JWT generator with the given secret and optional issuer/audience

func NewJWTGeneratorFromConfig

func NewJWTGeneratorFromConfig(config *Config) *JWTGenerator

NewJWTGeneratorFromConfig creates a JWT generator from configuration

func (*JWTGenerator) GenerateHealthCheckToken

func (j *JWTGenerator) GenerateHealthCheckToken(adminRole string) (string, error)

GenerateHealthCheckToken generates a short-lived token for health check purposes

func (*JWTGenerator) GenerateServiceToken

func (j *JWTGenerator) GenerateServiceToken(role string, service string, expiry time.Duration) (string, error)

GenerateServiceToken generates a long-lived service token

func (*JWTGenerator) GenerateToken

func (j *JWTGenerator) GenerateToken(role string, expiry time.Duration, claims map[string]interface{}) (string, error)

GenerateToken generates a JWT token with the specified role and expiry

func (*JWTGenerator) GetClaims

func (j *JWTGenerator) GetClaims(tokenString string) (jwt.MapClaims, error)

GetClaims extracts and validates claims from a token

func (*JWTGenerator) GetRole

func (j *JWTGenerator) GetRole(tokenString string) (string, error)

GetRole extracts the role from a token

func (*JWTGenerator) IsExpired

func (j *JWTGenerator) IsExpired(tokenString string) (bool, error)

IsExpired checks if a token is expired

func (*JWTGenerator) RemainingTime

func (j *JWTGenerator) RemainingTime(tokenString string) (time.Duration, error)

RemainingTime returns the remaining time until token expiry

func (*JWTGenerator) ValidateToken

func (j *JWTGenerator) ValidateToken(tokenString string) (*jwt.Token, error)

ValidateToken parses and validates a JWT token

Jump to

Keyboard shortcuts

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