tokenexchange

package
v0.68.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package tokenexchange provides OAuth 2.0 Token Exchange (RFC 8693) support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeTokenType

func NormalizeTokenType(tokenType string) (string, error)

NormalizeTokenType converts a short token type name to its full URN. Accepts both short forms ("access_token", "id_token", "jwt") and full URNs. Returns the full URN or an error if the token type is invalid.

This is primarily intended for CLI/user input processing. Internal APIs should use full URNs directly.

Types

type ExchangeConfig

type ExchangeConfig struct {
	// TokenURL is the OAuth 2.0 token endpoint URL
	TokenURL string

	// ClientID is the OAuth 2.0 client identifier
	ClientID string

	// ClientSecret is the OAuth 2.0 client secret
	ClientSecret string

	// Audience is the target audience for the exchanged token (optional per RFC 8693)
	Audience string

	// Scopes is the list of scopes to request (optional per RFC 8693)
	Scopes []string

	// SubjectTokenType specifies the type of the subject token being exchanged.
	// Common values: oauthproto.TokenTypeAccessToken (default), oauthproto.TokenTypeIDToken, oauthproto.TokenTypeJWT.
	// If empty, defaults to oauthproto.TokenTypeAccessToken.
	SubjectTokenType string

	// RequestedTokenType specifies the desired token type in the exchange response.
	// Defaults to oauthproto.TokenTypeAccessToken per RFC 8693. Set to any RFC 8693
	// token-type URN to request a different issued token type.
	RequestedTokenType string

	// Resource identifies the target resource per RFC 8693 Section 2.1 and RFC 8707.
	// Must be an absolute URI without a fragment. This implementation accepts a
	// single resource indicator; RFC 8707 permits multiple but multi-value support
	// is not yet exposed at this layer.
	Resource string

	// SubjectTokenProvider is a function that returns the subject token to exchange
	// we use a function to allow dynamic retrieval of the token (e.g. from request context)
	// and also to lazy-load the token only when needed, load from dynamic sources, etc.
	SubjectTokenProvider func() (string, error)

	// HTTPClient is the HTTP client to use for token exchange requests.
	// If nil, oauthproto.DefaultHTTPClient() will be used.
	HTTPClient *http.Client
}

ExchangeConfig holds the configuration for token exchange.

func (*ExchangeConfig) TokenSource

func (c *ExchangeConfig) TokenSource(ctx context.Context) oauth2.TokenSource

TokenSource returns an oauth2.TokenSource that performs token exchange.

func (*ExchangeConfig) Validate

func (c *ExchangeConfig) Validate() error

Validate checks if the ExchangeConfig contains all required fields.

Side effect: when SubjectTokenType is provided as a short form ("access_token", "id_token", "jwt"), Validate normalizes it to the full RFC 8693 URN and writes the result back onto the receiver. Callers in pkg/vmcp/auth/strategies/tokenexchange.go and pkg/runner/config_builder.go read the normalized value after Validate returns, so this mutation is part of the documented contract.

Jump to

Keyboard shortcuts

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