Skip to content

oauth: support the token exchange grant - #2500

Open
mjcheetham wants to merge 2 commits into
git-ecosystem:mainfrom
mjcheetham:oauth-tokenexchange
Open

mjcheetham wants to merge 2 commits into
git-ecosystem:mainfrom
mjcheetham:oauth-tokenexchange

Conversation

@mjcheetham

Copy link
Copy Markdown
Contributor

Add support for the RFC 8693 token-exchange grant to the shared OAuth2 client. This enables providers to exchange a token issued by an external identity provider for an OAuth access token accepted by the target host.

Expose GetTokenByTokenExchangeAsync with a subject token, its type, and the requested scopes. Add OAuth2TokenType and mappings for the standard token-type identifiers covering access tokens, refresh tokens, OpenID Connect ID tokens, and SAML 1.1/2.0 assertions.

Extend the in-memory OAuth server with subject-token grants and add tests for the exchange flow, token-type serialization, and parsing.

@mjcheetham
mjcheetham marked this pull request as ready for review November 9, 2026 14:08
@mjcheetham
mjcheetham requested a review from a team as a code owner November 9, 2026 14:08
@mjcheetham mjcheetham added the auth:oauth Specific to OAuth2 authentication label Nov 9, 2026
@mjcheetham
mjcheetham force-pushed the oauth-tokenexchange branch 3 times, most recently from 3155fa1 to 6fbe176 Compare November 10, 2026 14:35
@mjcheetham
mjcheetham requested a balanced review from Copilot November 17, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Token exchange may return a non-access token without validation, while the test server mishandles empty scopes and the API lacks JWT and target-parameter support.

4 open issues
What changed in this PR

Adds token-exchange support to the shared OAuth2 client, enabling host providers to exchange externally issued subject tokens for host access tokens.

Changes:

  • Exposes an asynchronous token-exchange API and request handling.
  • Adds token-type identifiers with enum serialization and parsing.
  • Extends the in-memory OAuth server and tests for the exchange flow.
File Description
src/​TestInfrastructure/​Objects/​TestOAuth2Server.cs Adds subject-token grants and exchange responses.
src/​Core/​Authentication/​OAuth/​OAuth2TokenType.cs Defines supported token types and wire-value conversions.
src/​Core/​Authentication/​OAuth/​OAuth2Constants.cs Adds token-type identifiers and exchange request constants.
src/​Core/​Authentication/​OAuth/​OAuth2Client.cs Adds the token-exchange API and HTTP request flow.
src/​Core.Tests/​Authentication/​OAuth2TokenTypeTests.cs Tests token-type serialization and parsing.
src/​Core.Tests/​Authentication/​OAuth2ClientTests.cs Tests a successful token exchange.

Review effort: Balanced

Technically application/x-www-form-urlencoded data can contain repeated
fields. Some OAuth RFCs allow for repeated fields, so we should support
this.

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
Allow providers to exchange an existing access or refresh token for
an OAuth access token, using the RFC 8693 token exchange grant.

This enables authentication flows where a token issued by an external
identity provider must be exchanged for one accepted by the host.

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth:oauth Specific to OAuth2 authentication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants