The oauth protocol component provides reusable OAuth 2.0 and PKCE functionality.
It includes:
Provider-specific URLs, scopes, configuration, and behavior should remain in provider-specific protocol components.
The OAuthClient communicates with OAuth authorization and token endpoints.
It can:
The create_pkce_pair() function generates:
The OAuthTokens type contains:
The is_expired() method can be used to determine whether an access token should be refreshed.
OAuthTokenStoreIf defines the interface for token storage implementations.
Token storage implementations are responsible for:
The OAuth protocol component does not prescribe a specific storage format or location.
OAuthRedirectServer receives a single OAuth redirect callback through a local HTTP server.
It extracts values such as:
A CLI component test is provided in the component_test directory.
Run the component test from the project root:
The test generates a PKCE verifier, challenge, state value, and example authorization URL.
Scopes can be supplied using repeated --scope arguments:
Provider endpoint values can also be supplied:
The component test does not contact an OAuth provider or exchange real tokens.
The OAuth component contains provider-independent OAuth behavior.
Provider-specific endpoints, scopes, token storage implementations, and authorization policies should be defined outside this component.