Documentation
¶
Overview ¶
Package token defines access-token issuing and verification independent of the token format.
Implementations: package jwt (HS256, EdDSA; standard library only) and the paseto module (PASETO v4). Verification errors wrap ErrInvalidToken.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidToken is returned (wrapped) for any token that fails parsing, // signature or claim validation. Callers should not distinguish further // in responses to clients. ErrInvalidToken = errors.New("token: invalid") // ErrExpiredToken is returned (wrapped together with ErrInvalidToken) // when the token is well-formed and authentic but past its expiry. ErrExpiredToken = errors.New("token: expired") )
Functions ¶
This section is empty.
Types ¶
type Claims ¶
type Claims struct {
SubjectID string // internal subject identifier
SessionID string // public session identifier ("sid"), optional
Roles []string // optional coarse-grained roles
Attrs map[string]string // optional attributes (org, tier, etc)
ID string // unique token ID ("jti"), set by issuer
Issuer string // set by issuer
Audience string // set by issuer
IssuedAt time.Time // set by issuer
ExpiresAt time.Time // set by issuer
}
Claims represents the canonical (normalized) claims embedded in an access token.
These claims are format-agnostic and stable. Fields marked "set by issuer" are ignored on input to Issue and filled in on output from Verify.
type Issuer ¶
type Issuer interface {
// Issue generates a signed or encrypted access token.
Issue(
ctx context.Context,
claims Claims,
) (string, error)
}
Issuer is responsible for minting/issuing access tokens.
An Issuer:
- signs tokens
- embeds claims
- controls expiry
An Issuer MUST NOT:
- validate refresh tokens
- talk to identity providers
- know about HTTP or transport
Implementations may be JWT, PASETO, or opaque tokens.
type Verifier ¶
type Verifier interface {
// Verify validates an access token and returns its claims.
Verify(
ctx context.Context,
accessToken string,
) (*Claims, error)
}
Verifier is responsible for validating access tokens and extracting embedded claims.
Implementations must:
- pin the expected algorithm per key (never trust the token header)
- validate token integrity
- validate issuer, audience and expiry
- extract normalized claims
Errors should wrap ErrInvalidToken (and ErrExpiredToken when expired).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package jwt issues and verifies JWT access tokens (RFC 7519, RFC 9068) using only the standard library.
|
Package jwt issues and verifies JWT access tokens (RFC 7519, RFC 9068) using only the standard library. |
|
Package keys holds signing and encryption keys for access tokens.
|
Package keys holds signing and encryption keys for access tokens. |