apitoken

package
v0.7.1 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateJTI added in v0.2.30

func GenerateJTI(aud, sub, act string) string

func GenerateKID

func GenerateKID(pubBytes []byte) string

Types

type KeyPair

type KeyPair struct {
	ActiveKey bool
	KeyId     string
	PublicKey *paseto.V4AsymmetricPublicKey
	SecretKey *paseto.V4AsymmetricSecretKey
}

func LoadKeysFromSecret

func LoadKeysFromSecret(secret *corev1.Secret, isActive bool) (*KeyPair, error)

LoadKeysFromSecret loads an key pair from a Kubernetes Secret.

type KeyPairs

type KeyPairs []*KeyPair

func GenerateDevmodeKeyPair

func GenerateDevmodeKeyPair() *KeyPairs

func (*KeyPairs) ActiveKey

func (p *KeyPairs) ActiveKey() *KeyPair

func (*KeyPairs) GetKey

func (p *KeyPairs) GetKey(kid string) (*KeyPair, bool)

type TokenData

type TokenData struct {
	Action     string `json:"act"`
	Audience   string `json:"aud"`
	Expiration int64  `json:"exp"`
	IssuedAt   int64  `json:"iat"`
	Issuer     string `json:"iss"`
	JTI        string `json:"jti"`
	KID        string `json:"kid"`
	NotBefore  int64  `json:"nbf"`
	Scope      string `json:"scp"`
	Subject    string `json:"sub"`
}

type TokenManager

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

func APITokenManagerLoader

func APITokenManagerLoader(
	issuer string,
	secrets kdexv1alpha1.Secrets,
	revocationCache cache.Cache,
	devMode bool,
) (*TokenManager, error)

func NewTokenManager

func NewTokenManager(issuer string, keyPairs *KeyPairs, revocationCache cache.Cache) (*TokenManager, error)

func (*TokenManager) KeyPairs

func (tm *TokenManager) KeyPairs() KeyPairs

func (*TokenManager) MintStatelessKey

func (tm *TokenManager) MintStatelessKey(aud string, sub string, action string, scope string, ttl time.Duration) (string, error)

func (*TokenManager) RevokeByMetadata added in v0.2.30

func (tm *TokenManager) RevokeByMetadata(ctx context.Context, aud, sub, act string, ttl time.Duration) error

func (*TokenManager) RevokeToken added in v0.2.30

func (tm *TokenManager) RevokeToken(ctx context.Context, signed string) error

func (*TokenManager) TokenPrefix added in v0.3.0

func (tm *TokenManager) TokenPrefix() string

TokenPrefix returns this host's white-label API token prefix (empty when prefixing is off). Callers that need to discriminate a brand-prefixed PAT on the wire (e.g. the Bearer auth path) use this to recognize the prefix without reaching into the manager's internals.

func (*TokenManager) ValidateToken

func (tm *TokenManager) ValidateToken(ctx context.Context, signed, expectedAudience string) (*TokenData, error)

ValidateToken parses and verifies a PASETO API token.

expectedAudience is REQUIRED in spirit but technically optional in signature:

  • non-empty: a paseto.ForAudience rule is added so a token minted for a different audience is rejected. This is the correct mode for any handler that uses ValidateToken's success as proof the bearer should be granted access on the receiving party.
  • empty: the audience check is skipped. This is ONLY appropriate when the token is being INSPECTED (e.g. to extract its subject for a revocation flow) — not when validating for use. Passing "" in any other context is the kdex-tech/host-manager#69 confused-deputy regression.

func (*TokenManager) WithTokenPrefix added in v0.2.94

func (tm *TokenManager) WithTokenPrefix(prefix string) *TokenManager

WithTokenPrefix sets this host's white-label API token prefix. Prefixing is off by default (empty), in which case tokens are emitted as bare "v4.public." PASETO strings. When set, the prefix REPLACES the PASETO header on the wire (see wrap/unwrap). Returns the receiver for chaining. This is the single configuration point for the prefix; the controller sources it from KDexHost.spec.auth.apiToken.tokenPrefix (falling back to the NexusConfiguration default) and calls this once per host.

Jump to

Keyboard shortcuts

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