-
-
Notifications
You must be signed in to change notification settings - Fork 6
allow to use league/oauth2-google without leafs/leaf #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -98,22 +98,35 @@ public function __construct() | |||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||
| class_exists('League\OAuth2\Client\Provider\Google') && | ||||||||||||||||||||||||||||||||||||
| _env('GOOGLE_AUTH_CLIENT_ID') && | ||||||||||||||||||||||||||||||||||||
| _env('GOOGLE_AUTH_CLIENT_SECRET') | ||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||
| 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'), | ||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||
| 'name' => 'google', | ||||||||||||||||||||||||||||||||||||
| 'redirectUri' => _env('GOOGLE_AUTH_REDIRECT_URI', _env('APP_URL') . '/auth/register/google'), | ||||||||||||||||||||||||||||||||||||
| 'redirectUri' => $this->env( | ||||||||||||||||||||||||||||||||||||
| 'GOOGLE_AUTH_REDIRECT_URI', | ||||||||||||||||||||||||||||||||||||
| $this->env('APP_URL') . '/auth/register/google' | ||||||||||||||||||||||||||||||||||||
| ) ?: '', | ||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /** @return mixed Returns the value of the environment variable by using Leaf's `_env` primarily */ | ||||||||||||||||||||||||||||||||||||
| private function env(string $name, $default = false) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| // If `_env` function of Leaf is defined, use it. | ||||||||||||||||||||||||||||||||||||
| if (function_exists('_env')) { | ||||||||||||||||||||||||||||||||||||
| return _env($name, $default); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Return the value if found, otherwise false like getenv(). | ||||||||||||||||||||||||||||||||||||
| return $_ENV[$name] ?? $default; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+124
to
+125
|
||||||||||||||||||||||||||||||||||||
| // 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; |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 /**.
| /** |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new env-based auto-
withGoogle()path in__construct()isn’t covered by tests. Consider adding a small Pest test that sets values viaputenv()/$_SERVER(without Leaf’s_env()present) and asserts the Google client is registered whenleague/oauth2-googleis installed.