allow to use league/oauth2-google without leafs/leaf#46
allow to use league/oauth2-google without leafs/leaf#46fadrian06 wants to merge 1 commit intoleafsphp:v4.xfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the hard dependency on Leaf’s _env() helper for Google OAuth auto-configuration so league/oauth2-google can be used without requiring leafs/leaf.
Changes:
- Replace direct
_env()usage in Google OAuth auto-setup with an internalenv()helper. - Add
Auth::env()to read environment variables with Leaf_env()as a preferred source. - Bump
league/oauth2-googledev dependency from^4.0to^5.0.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/Auth.php |
Introduces env() helper and updates Google OAuth auto-setup/default redirect URI logic to use it. |
composer.json |
Updates league/oauth2-google version in require-dev. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| /** |
There was a problem hiding this comment.
There’s an extra /** starting at line 128 (and another /** on line 130) which makes this docblock malformed and harder for tooling (PHPStan/PHPDoc generators) to parse. Remove the stray opener so the connect() docblock starts cleanly with a single /**.
| /** |
| * name?: string, | ||
| * redirectUri?: string, | ||
| * } $options | ||
| * } $options If `$options['redirectUri']` is not set, it will default to `$_ENV['APP_URL']/auth/google/callback` |
There was a problem hiding this comment.
PHPDoc for withGoogle() says the default redirect URI is based on $_ENV['APP_URL'], but the implementation now uses $this->env('APP_URL') (which may resolve via Leaf _env() or other sources). Update the docstring to match the actual behavior (and clarify behavior when APP_URL is unset).
| * } $options If `$options['redirectUri']` is not set, it will default to `$_ENV['APP_URL']/auth/google/callback` | |
| * } $options If `$options['redirectUri']` is not set, it will default to the value of `APP_URL` (as resolved by this class's environment helper) with `/auth/google/callback` appended; if `APP_URL` is unset or empty, the default will be `/auth/google/callback`. |
| // Return the value if found, otherwise false like getenv(). | ||
| return $_ENV[$name] ?? $default; |
There was a problem hiding this comment.
Non-Leaf fallback reads only from $_ENV. Environment variables are often exposed via getenv()/$_SERVER without populating $_ENV, so this can return the default even when the variable is set. Consider falling back to $_SERVER[$name] and/or getenv($name) before returning $default.
| // Return the value if found, otherwise false like getenv(). | |
| return $_ENV[$name] ?? $default; | |
| // Prefer $_ENV, then $_SERVER, then getenv(), finally falling back to the provided default. | |
| if (isset($_ENV[$name])) { | |
| return $_ENV[$name]; | |
| } | |
| if (isset($_SERVER[$name])) { | |
| return $_SERVER[$name]; | |
| } | |
| $value = getenv($name); | |
| if ($value !== false) { | |
| return $value; | |
| } | |
| return $default; |
| if ($this->env('GOOGLE_AUTH_CLIENT_ID') && $this->env('GOOGLE_AUTH_CLIENT_SECRET') && class_exists(Google::class)) { | ||
| $this->withGoogle( | ||
| _env('GOOGLE_AUTH_CLIENT_ID'), | ||
| _env('GOOGLE_AUTH_CLIENT_SECRET'), | ||
| $this->env('GOOGLE_AUTH_CLIENT_ID'), | ||
| $this->env('GOOGLE_AUTH_CLIENT_SECRET'), | ||
| [ |
There was a problem hiding this comment.
The new env-based auto-withGoogle() path in __construct() isn’t covered by tests. Consider adding a small Pest test that sets values via putenv()/$_SERVER (without Leaf’s _env() present) and asserts the Google client is registered when league/oauth2-google is installed.
What kind of change does this PR introduce? (pls check at least one)
Description
Previously you have to install both league/oauth2-google and leafs/leaf to call ->withGoogle() within __construct().
Does this PR introduce a breaking change? (check one)