sign

package
v0.4.16 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 13 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

This section is empty.

Types

type Signer

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

func NewSigner

func NewSigner(
	audience string,
	duration time.Duration,
	issuer string,
	privateKey *crypto.Signer,
	kid string,
	mapper *dmapper.Mapper,
) (*Signer, error)

NewSigner creates a new signer.

func (*Signer) Duration added in v0.2.78

func (s *Signer) Duration() time.Duration

Duration returns the lifetime each signed token is valid for. Cache implementations should subtract a skew from this to ensure a cached token always has meaningful remaining life on hit.

func (*Signer) Project added in v0.2.78

func (s *Signer) Project(signingContext jwt.MapClaims) (jwt.MapClaims, error)

Project derives the deterministic claim set that will be signed for a given signingContext. iat/exp/jti are deliberately omitted: they identify the token, not the identity, and putting them in the projection defeats the caller's ability to use the projection as a cache key.

The signer's audience is the AUTHORITATIVE outbound aud: Project is always called to re-issue a token for a SPECIFIC downstream target (the per-function FAT path in proxy.go), and re-using the inbound aud would make the issued token transferable to a different audience than the signer was configured for. Concretely: a user logs in at the host (aud=["https://<host>"]) and then calls a function; proxy.go builds a signer with audience=fn.Status.URL, but the previous logic reused the inbound host aud, so the function rejected the FAT with "token has invalid audience". Always use s.audience.

func (*Signer) Sign

func (s *Signer) Sign(signingContext jwt.MapClaims) (string, error)

Sign is a convenience wrapper that runs Project then SignProjected. Direct callers that want to cache should call the two steps separately so the cache key reflects the deterministic projection rather than the raw inbound context (which routinely includes per-request headers like Traceparent that defeat the cache).

func (*Signer) SignProjected added in v0.2.78

func (s *Signer) SignProjected(projected jwt.MapClaims) (string, error)

SignProjected attaches the per-token identifiers (iat/exp/jti) to an already-projected claim set and signs it. Use this in tandem with Project when caching to skip the projection step on a cache hit.

The projection has the LAST WORD on every field — including iat/exp/jti. The original Sign emitted mapper output last via maps.Copy, and several call sites depend on that semantic (e.g. dev-mode tests that inject exp=-1 via a ClaimMappings rule to synthesize an expired token). Default iat/exp/jti are written first, then maps.Copy(outboundClaims, projected) overrides anything the projection already carries.

func (*Signer) SignScoped added in v0.4.15

func (s *Signer) SignScoped(signingContext jwt.MapClaims, grantedScopes []string) (string, error)

SignScoped is Sign with OAuth scope confinement: it projects the context (which runs the ClaimMappings mapper and Compact), removes the scope-controlled claim families absent from grantedScopes, then signs. Confinement runs AFTER the mapper, so a ClaimMappings rule that injects into a scope-controlled family cannot smuggle it into a token whose scope did not grant it — regardless of which source claim the rule reads. Used by the primary subject mints (LoginLocal, mintTokensFromCode, mintTokensFromSubject); FAT projection, mint_token, OIDC exchange, and client_credentials keep raw Sign/Project. See kdex-tech/host-manager#140.

Jump to

Keyboard shortcuts

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