Skip to content

[codex] Support redirect_uri config in Google userFromCode flow#303

Merged
overtrue merged 5 commits into
4.xfrom
feat/google-auto-redirect-uri
Mar 16, 2026
Merged

[codex] Support redirect_uri config in Google userFromCode flow#303
overtrue merged 5 commits into
4.xfrom
feat/google-auto-redirect-uri

Conversation

@overtrue

@overtrue overtrue commented Mar 16, 2026

Copy link
Copy Markdown
Owner

Problem

When users configure OAuth with redirect_uri only, token exchange in userFromCode() could miss redirect_uri in the token request body (for example, Google returning Missing parameter: redirect_uri).

Root Cause

Internal config normalization used legacy aliases (redirect / redirect_url) as primary sources. If only redirect_uri was provided, the provider's internal redirect value could be empty in some flows.

Fix

The normalization is now done in the base provider so all providers benefit consistently:

  1. Normalize legacy aliases to the RFC key redirect_uri.
  2. Keep redirect_url as a compatibility mirror.
  3. Use normalized redirect_uri as the source for $this->redirectUrl.
  4. Keep withRedirectUrl() in sync by writing both redirect_uri and redirect_url.

Token exchange already uses base getTokenFields(), which sends:

  • code
  • redirect_uri

So after normalization, userFromCode() token requests include redirect_uri automatically.

Tests

Added/updated tests to prove behavior:

  • tests/Providers/GoogleTest.php::test_google_user_from_code_uses_redirect_uri_config_key
    • Asserts token POST body includes redirect_uri=https://example.com/callback when config only has redirect_uri.
  • tests/OAuthTest.php
    • Added alias coverage for redirect_uri and redirect in auth URL generation.

Docs

Updated examples in README.md and README_EN.md to use redirect_uri as the standard key, while documenting redirect and redirect_url as legacy aliases.

Validation

Executed locally:

  • vendor/bin/phpunit tests/Providers/GoogleTest.php
  • vendor/bin/phpunit tests/OAuthTest.php
  • vendor/bin/phpunit

All tests pass (existing suite-level warning/deprecation output remains unchanged).

Copilot AI review requested due to automatic review settings March 16, 2026 06:46

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.

Pull request overview

Adds compatibility for Google OAuth configs that use the standard redirect_uri key so userFromCode() includes redirect_uri during the token exchange, preventing Google “Missing parameter: redirect_uri” failures.

Changes:

  • Add a Google provider constructor fallback mapping redirect_uriredirect_url when no redirect is otherwise configured.
  • Add a provider-level test asserting the token request includes redirect_uri when only redirect_uri is supplied in config.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Providers/Google.php Adds config fallback so Google token exchange includes redirect_uri when configured via redirect_uri.
tests/Providers/GoogleTest.php New test covering userFromCode() token request body includes redirect_uri from config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Providers/Google.php Outdated
@overtrue overtrue merged commit f84c759 into 4.x Mar 16, 2026
29 checks passed
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.

2 participants