Skip to content

allow to use league/oauth2-google without leafs/leaf#46

Open
fadrian06 wants to merge 1 commit intoleafsphp:v4.xfrom
fadrian06:google-client-without-app
Open

allow to use league/oauth2-google without leafs/leaf#46
fadrian06 wants to merge 1 commit intoleafsphp:v4.xfrom
fadrian06:google-client-without-app

Conversation

@fadrian06
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce? (pls check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe below

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)

  • Yes
  • No

Copilot AI review requested due to automatic review settings April 2, 2026 13:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 internal env() helper.
  • Add Auth::env() to read environment variables with Leaf _env() as a preferred source.
  • Bump league/oauth2-google dev dependency from ^4.0 to ^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.

Comment on lines +129 to 130

/**
Copy link

Copilot AI Apr 2, 2026

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 /**.

Suggested change
/**

Copilot uses AI. Check for mistakes.
* name?: string,
* redirectUri?: string,
* } $options
* } $options If `$options['redirectUri']` is not set, it will default to `$_ENV['APP_URL']/auth/google/callback`
Copy link

Copilot AI Apr 2, 2026

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).

Suggested change
* } $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`.

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +125
// Return the value if found, otherwise false like getenv().
return $_ENV[$name] ?? $default;
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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 uses AI. Check for mistakes.
Comment on lines +101 to 105
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'),
[
Copy link

Copilot AI Apr 2, 2026

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 via putenv()/$_SERVER (without Leaf’s _env() present) and asserts the Google client is registered when league/oauth2-google is installed.

Copilot uses AI. Check for mistakes.
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