Skip to content

fix(auth): correct OAuth authorization types to match API responses - #2088

Merged
mandarini merged 1 commit into
masterfrom
fix/auth-types
Feb 4, 2026
Merged

mandarini merged 1 commit into
masterfrom
fix/auth-types

Conversation

@mandarini

@mandarini mandarini commented Feb 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixed incorrect field names and enhanced type safety for OAuth 2.1 authorization server APIs.

Changes:

  • Changed OAuthAuthorizationDetails.redirect_url → redirect_uri (matches GoTrueAPI field name)
  • Made redirect_uri required (API always returns this field when consent is needed)
  • Added OAuthRedirect type for already-consented/post-consent responses
  • Added union type to AuthOAuthAuthorizationDetailsResponse (OAuthAuthorizationDetails | OAuthRedirect)
  • Consolidated duplicate redirect response types by reusing OAuthRedirect
  • Fixed JSDoc comments in types.ts and GoTrueClient.ts to reference correct field names
  • Enhanced JSDoc with usage examples, type narrowing guidance, and behavioral details

Root Cause:

PR #1891 (Nov 2025) incorrectly changed redirect_uri to redirect_url. However, the GoTrue API intentionally uses two different field names:

  • redirect_uri: Base redirect URI from client registration (in AuthorizationDetailsResponse)
  • redirect_url: Complete redirect URL with code/state parameters (in ConsentResponse)

From Auth server code:

The original implementation in PR #1793 (Oct 2025) had the correct field name.

Type Safety Impact:

The union type now requires developers to narrow the response type using TypeScript's discriminated unions ('authorization_id' in data), preventing runtime errors when accessing fields that may not exist in the already-consented case.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added OAuth grant management: ability to list and revoke user OAuth grants
    • Enhanced OAuth redirect handling in authorization flow
  • Documentation

    • Updated OAuth authorization documentation with improved type guidance

@github-actions github-actions Bot added the auth-js Related to the auth-js library. label Feb 4, 2026
@coderabbitai

coderabbitai Bot commented Feb 4, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Two files in the auth-js package are updated: GoTrueClient.ts receives a minor documentation revision regarding OAuth redirect terminology, while lib/types.ts introduces new OAuth types and extends the GoTrueAdminOAuthApi interface with grant management methods.

Changes

Cohort / File(s) Summary
Documentation Update
packages/core/auth-js/src/GoTrueClient.ts
Minor documentation correction updating redirect field terminology from redirect_uri to redirect_url in OAuth authorization details.
OAuth Types & API Surface
packages/core/auth-js/src/lib/types.ts
Introduced new types: OAuthRedirect and OAuthGrant with associated response types. Modified OAuthAuthorizationDetails (removed redirect_url, added redirect_uri). Changed AuthOAuthAuthorizationDetailsResponse to union type. Updated AuthOAuthConsentResponse structure. Extended GoTrueAdminOAuthApi with listGrants() and revokeGrant() methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/auth-types

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mandarini mandarini self-assigned this Feb 4, 2026
@mandarini
mandarini requested a review from cemalkilic February 4, 2026 14:32
@mandarini
mandarini marked this pull request as ready for review February 4, 2026 14:37
@mandarini
mandarini requested review from a team as code owners February 4, 2026 14:37
@mandarini
mandarini merged commit 5d29d9b into master Feb 4, 2026
21 of 22 checks passed
@mandarini
mandarini deleted the fix/auth-types branch February 4, 2026 14:38
@mandarini mandarini linked an issue Feb 4, 2026 that may be closed by this pull request
7 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth-js Related to the auth-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

return type of getAuthorizationDetails is wrong

2 participants