Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement POST /oauth/token handler that exchanges authorization codes for access tokens using fosite's access request/response flow. The handler validates the incoming token request, retrieves the stored authorization session, generates JWT access tokens, and supports RFC 8707 resource parameter for audience-restricted tokens targeting specific MCP servers.
This handler completes the OAuth 2.0 authorization code flow started by the authorize and callback handlers. When a client presents an authorization code, fosite retrieves the session that was stored during the callback phase - this session contains the user's subject, the upstream token session ID (tsid), and the client ID binding. The token endpoint uses these stored claims to generate the access token, maintaining the link between issued tokens and upstream IDP tokens for later token injection by the proxy middleware. The test infrastructure is extended to properly track authorization code and PKCE sessions across the full authorize→callback→token flow.