Skip to content

Support custom token response parsing for non-standard OAuth providers - #9

Merged
joshuaclayton merged 4 commits into
mainfrom
allow-swapped-token-responses
Apr 6, 2026
Merged

Support custom token response parsing for non-standard OAuth providers#9
joshuaclayton merged 4 commits into
mainfrom
allow-swapped-token-responses

Conversation

@joshuaclayton

Copy link
Copy Markdown
Owner

No description provided.

joshuaclayton and others added 4 commits April 4, 2026 22:21
…access

Introduce a TokenResponseFields struct and TokenResponse::into_fields()
conversion so that exchange_code() and exchange_refresh_token() work
through an intermediate fields struct rather than accessing TokenResponse
directly. This prepares for allowing custom token response types in a
follow-up commit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Support providers like Slack that nest tokens inside sub-objects by
allowing callers to specify a custom deserialization type via
`.token_response_type::<R>()` on the builder. The type must implement
`DeserializeOwned + Into<TokenResponseFields>`.

- Add `TokenResponseFields` as the canonical token response struct with
  builder-style construction (`new(access_token).with_*()`)
- Default path deserializes `TokenResponseFields` directly (no
  intermediate type needed for standard OAuth 2.0 responses)
- Add `TokenParse` error variants to `AuthError` and `RefreshError`
- Add `FakeOAuthServer::start_with_nested_response` for testing
- Use `checked_add` for `expires_in` expiry calculation
- Include response body in refresh token parse errors (parity with
  auth code exchange)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ed scopes

PageContext.scopes() was passing the builder-configured scopes to the
success page renderer instead of the scopes resolved from the token
response (per RFC 6749 §5.1). This caused the success page to show
requested scopes even when the provider granted a different set.

Also adds FakeOAuthServer::start_with_scope() for testing providers
that return an explicit scope in the token response.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Demonstrates handling Slack's deviations from RFC 6749: nested
authed_user response, comma-delimited scopes, non-standard user_scope
parameter, and HTTPS redirect requirement.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@joshuaclayton
joshuaclayton merged commit 9f474ff into main Apr 6, 2026
8 checks passed
@joshuaclayton
joshuaclayton deleted the allow-swapped-token-responses branch April 6, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant