auth

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Generic Claims
	ClaimIss           = "iss"
	ClaimClientId      = "client_id"
	ClaimApplicationId = "application_id"
	ClaimAud           = "aud"
	ClaimNbf           = "nbf"
	ClaimAzp           = "azp"
	ClaimExp           = "exp"
	ClaimIat           = "iat"
	ClaimSub           = "sub"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsumerAssertion

type ConsumerAssertion struct {
	ApplicationID string   // Mapped from 'application_id'
	ClientID      string   // Mapped from 'client_id'
	Subscriber    string   // Mapped from 'sub' or 'azp'
	Iss           string   // Mapped from 'iss'
	Aud           []string // Mapped from 'aud'
	Exp           int64    // Mapped from 'exp'
	Iat           int64    // Mapped from 'iat'
}

ConsumerAssertion represents the parsed and validated M2M token claims.

func GetConsumerJwtFromToken

func GetConsumerJwtFromToken(jwtConfig *configs.JWTConfig, trustUpstream bool, r *http.Request) (*ConsumerAssertion, error)

GetConsumerJwtFromToken validates and parses JWT token from HTTP request

func GetConsumerJwtFromTokenWithValidator

func GetConsumerJwtFromTokenWithValidator(jwtConfig *configs.JWTConfig, trustUpstream bool, r *http.Request, validator *TokenValidator) (*ConsumerAssertion, error)

GetConsumerJwtFromTokenWithValidator validates and parses JWT token with optional cached validator

type TokenValidator

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

TokenValidator handles JWT token validation with auto-refreshing JWKS. The JWKS is automatically refreshed in the background to handle key rotation.

func NewTokenValidator

func NewTokenValidator(ctx context.Context, jwksURL string, environment string) (*TokenValidator, error)

NewTokenValidator creates a new TokenValidator instance with automatic JWKS refresh. The provided context controls the lifecycle of the background refresh goroutine. When the context is cancelled, the refresh goroutine will stop.

Implementation uses keyfunc.NewDefaultOverrideCtx with a custom HTTP client that:

  • Filters x5c certificates from JWKS (prevents parsing errors)
  • Fetches JWKS immediately (fail-fast validation)
  • Starts background goroutine to refresh JWKS every hour
  • Handles automatic key rotation
  • Refreshes on unknown kid (rate-limited to prevent abuse)

This ensures:

  1. Service won't start if JWKS is unavailable (when trustUpstream=false)
  2. Automatic key rotation handling without manual intervention
  3. High availability during key rotation periods
  4. No x5c certificate parsing errors

Jump to

Keyboard shortcuts

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