Documentation
¶
Index ¶
- type Config
- type JWTGenerator
- func (j *JWTGenerator) GenerateHealthCheckToken(adminRole string) (string, error)
- func (j *JWTGenerator) GenerateServiceToken(role string, service string, expiry time.Duration) (string, error)
- func (j *JWTGenerator) GenerateToken(role string, expiry time.Duration, claims map[string]interface{}) (string, error)
- func (j *JWTGenerator) GetClaims(tokenString string) (jwt.MapClaims, error)
- func (j *JWTGenerator) GetRole(tokenString string) (string, error)
- func (j *JWTGenerator) IsExpired(tokenString string) (bool, error)
- func (j *JWTGenerator) RemainingTime(tokenString string) (time.Duration, error)
- func (j *JWTGenerator) ValidateToken(tokenString string) (*jwt.Token, error)
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