token

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package token implements the OIDC Token endpoint plugin.

It handles POST /token (RFC 6749 §3.2 / OIDC Core §3.1.3.1), supporting the following grant types:

  • authorization_code (RFC 6749 §4.1.3, OIDC Core §3.1.3.1)
  • refresh_token (RFC 6749 §6)
  • client_credentials (RFC 6749 §4.4)
  • urn:ietf:params:oauth:grant-type:jwt-bearer (RFC 7523 §2.1)
  • urn:ietf:params:oauth:grant-type:device_code (RFC 8628 §3.4)
  • urn:ietf:params:oauth:grant-type:token-exchange (RFC 8693)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	TokenStore  storm.TokenStore
	ClientStore storm.ClientStore
	AuthStore   storm.AuthStore
	CIBAStore   storm.CIBAStore // optional, for CIBA grant type
	Crypto      storm.UniCrypto
	KeyStore    storm.KeyStore
	Decoder     *protocol.Decoder
	Logger      *slog.Logger
	// AuditLogger receives structured audit events for token issuance and auth failures.
	// When nil, events are logged via slog as a fallback.
	AuditLogger storm.AuditLogger
	// DevicePollInterval is the default polling interval for device_code grant (default: 5s).
	DevicePollInterval time.Duration
	// RequireDPoP when true requires a valid DPoP proof for all token requests.
	// Requests without a DPoP proof are rejected with invalid_request.
	// Use this for FAPI 2.0 compliance (sender-constrained tokens via DPoP).
	RequireDPoP bool
	// RequireMtls when true requires a valid mTLS client certificate for all token requests.
	// Requests without a client certificate are rejected with invalid_request.
	// Use this for FAPI 2.0 compliance (sender-constrained tokens via mTLS).
	RequireMtls bool
	// AllowPrivateIPs disables SSRF protection for jwks_uri fetches (testing only).
	AllowPrivateIPs bool
	// SkipTLSCertVerify disables TLS certificate verification on outbound HTTP (testing only).
	SkipTLSCertVerify bool
	// SessionRecorder records client sessions for back-channel logout (optional).
	SessionRecorder storm.ClientSessionRecorder
	// InvalidateRefreshOnUse when true passes the old refresh token to
	// CreateAccessAndRefreshTokens so the storage can atomically invalidate it.
	// This is required by RFC 6749 §10.4 (refresh token rotation) and prevents
	// stolen refresh tokens from being reused. Default: false for backward
	// compatibility with conformance tests. Enable for production deployments.
	InvalidateRefreshOnUse bool
}

Config holds the dependencies for the Token plugin.

type DPoPNonceSender

type DPoPNonceSender interface {
	// WriteNonceHeader writes the DPoP-Nonce HTTP header to the response.
	WriteNonceHeader(w http.ResponseWriter)
}

DPoPNonceSender is optionally implemented by a plugin to provide DPoP server-provided nonce support (RFC 9449 §8).

When implemented, the token endpoint includes a DPoP-Nonce header in successful token responses, allowing the server to rotate nonces.

type Plugin

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

Plugin implements the OIDC Token endpoint.

func New

func New(ctx *storm.PluginContext) *Plugin

New creates a new Token plugin from a PluginContext.

func NewWithConfig

func NewWithConfig(cfg Config) *Plugin

NewWithConfig creates a new Token plugin with explicit config.

func (*Plugin) Category

func (p *Plugin) Category() storm.PluginCategory

Category returns CategoryCore — token is a required OAuth 2.0 endpoint.

func (*Plugin) Contribute

func (p *Plugin) Contribute(ctx context.Context, cfg *protocol.DiscoveryConfiguration)

Contribute returns the discovery fields for the token endpoint.

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the plugin name.

func (*Plugin) Register

func (p *Plugin) Register(r chi.Router)

Register installs the POST /token route.

func (*Plugin) Requires

func (p *Plugin) Requires() []string

Requires returns the storage dependencies.

func (*Plugin) SetDPoPNonceSender

func (p *Plugin) SetDPoPNonceSender(sender DPoPNonceSender)

SetDPoPNonceSender sets the DPoP nonce sender for server-provided nonces. Called by the Engine during Build when both token and dpop plugins are present.

Jump to

Keyboard shortcuts

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