Draft
Conversation
6dc2c94 to
0fbab4c
Compare
There was a problem hiding this comment.
Pull request overview
Introduces a first-party OAuth login flow (via Laravel Socialite) integrated with Craft’s existing authentication rules, user creation/linking, and login UI (CP + site), gated to Pro+ editions.
Changes:
- Add OAuth manager/service + controller + routes to support redirect/callback flows and identity linking.
- Extend configuration (
GeneralConfig::oauthProviders) and template rendering to show OAuth login buttons. - Add supporting utilities (group resolution), edition capability flag, and comprehensive tests.
Reviewed changes
Copilot reviewed 45 out of 47 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| composer.json | Adds laravel/socialite dependency. |
| composer.lock | Locks Socialite and transitive packages. |
| testbench.yaml | Registers Socialite provider for testbench. |
| yii2-adapter/testbench.yaml | Registers Socialite provider for adapter testbench. |
| yii2-adapter/composer.lock | Locks adapter dependencies including Socialite. |
| src/Auth/OAuth/OAuth.php | Core OAuth manager: provider normalization, button rendering, identity linking, Socialite driver building. |
| src/Auth/OAuth/Actions/* | Default strategy implementations (identity/user/group/button). |
| src/Auth/OAuth/Contracts/* | Strategy extension points for customization. |
| src/Auth/OAuth/Data/* | DTOs for providers and button rendering. |
| src/Auth/OAuth/Events/ResolvingOAuthUserLink.php | Event hook for custom user linking. |
| src/Auth/OAuth/Exceptions/ProviderConfigurationException.php | Exception type for invalid provider configs. |
| src/Http/Controllers/Auth/OAuthController.php | Redirect + callback endpoints and login finalization behavior. |
| routes/web.php | Adds OAuth redirect/callback routes gated by Pro edition. |
| src/Config/GeneralConfig.php | Adds oauthProviders config + docs + setter. |
| src/User/UserGroups.php | Adds resolveGroup() to normalize group references (id/uid/handle). |
| src/User/Elements/User.php | Switches SSO identity check to OAuth service + Pro gating. |
| src/Edition.php | Adds supportsOAuth() capability flag. |
| yii2-adapter/legacy/web/twig/variables/CraftVariable.php | Exposes craft.oauth to Twig. |
| src/Http/Controllers/Auth/AuthenticationController.php | Extracts shared finalizeLogin() and tweaks CP view lookup. |
| src/Http/Controllers/Auth/LoginController.php | Uses finalizeLogin() to centralize 2FA branching. |
| resources/templates/login.twig | Passes initial login error into shared login partial. |
| resources/templates/_special/login.twig | Renders initial error + swaps old SSO provider rendering for OAuth buttons. |
| docs/oauth.md | New end-user/dev documentation for OAuth feature. |
| tests/Unit/EditionTest.php | Tests OAuth support by edition. |
| tests/TestClasses/OAuth/* | Test doubles for providers and customization strategies. |
| tests/Feature/Auth/OAuth/* | Feature tests for OAuth manager + default strategies. |
| tests/Feature/Http/Controllers/Auth/OAuthControllerTest.php | Feature tests for redirect/callback flows, account creation/linking/groups, customization. |
| tests/Feature/Http/Controllers/Auth/LoginControllerTest.php | Ensures flashed CP login errors render. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
# Conflicts: # yii2-adapter/composer.lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OAuth providers are defined in
GeneralConfig::oauthProviders(), keyed by a handle likegoogleorgithub. Each provider needs adriver, which can be a registered Socialite driver name or a Socialite-compatible provider class. Craft uses its own redirect and callback routes, but the callback URL you register with the provider should be Craft’s stable site callback, such ashttp://example.com/oauth/google/callback.By default, Craft resolves the external identity from
SocialiteUser::getId(), tries to match an existing Craft user via an existingsso_identitieslink or the provider email, and can create a new user ifcreatesUsersallows it. New users can be assigned groups, optionally activated immediately, and the resulting login goes through normal Craft access checks while skipping the 2FA prompt. If you need custom behavior, you can swap in resolver/populator/renderer classes for identity matching, user matching, user population, group assignment, and button rendering.Configured OAuth buttons appear automatically on the login page.