feat(auth): OAuth Console login (Google, Facebook, Office365, Apple)#213
Open
Amein-Eskinder wants to merge 1 commit into
Open
feat(auth): OAuth Console login (Google, Facebook, Office365, Apple)#213Amein-Eskinder wants to merge 1 commit into
Amein-Eskinder wants to merge 1 commit into
Conversation
Implements server-side OAuth handlers for Console login per fleetbase/fleetbase#453. * AuthController::loginWith{Google,Facebook,Office365,Apple} + shared oauthRespond helper handling find-or-create-and-link user, 2FA gating, and Sanctum token issuance — response shape matches the native /int/v1/auth/login endpoint exactly. * New FacebookVerifier validates access tokens server-side via Graph API /debug_token authenticated with the app token; refuses if the client-supplied app_id mismatches the server config. The existing storefront CustomerController::loginWithFacebook trusts a client-supplied facebookUserId without verification — that gap is closed here for the Console flow and worth a separate backport to the storefront. * New Office365Verifier validates Microsoft ID tokens against the tenant JWKS via lcobucci/jwt, mirroring AppleVerifier's shape. * Existing GoogleVerifier and AppleVerifier are reused. The Apple handler wraps the verifier call in try/catch because AppleVerifier::verifyAppleJwt throws on malformed JWT input (Google/Facebook/Office365 verifiers return null on any failure — Apple's behaviour was inconsistent and would surface as a 500 to an end user POSTing junk). * User.\$fillable gains microsoft_user_id; companion migration adds the nullable+unique column to users. * Four new routes under /int/v1/auth/oauth/* sit behind the existing ThrottleRequests middleware. No new dependencies — google/apiclient and lcobucci/jwt are already in core-api/composer.json.
4 tasks
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.
Implements the server-side half of fleetbase/fleetbase#453 — OAuth login for the Console with four providers. Companion frontend PR is open against
fleetbase/fleetbase(Console UI buttons + i18n + per-provider SDK glue).What's in this PR
POST /int/v1/auth/oauth/{google,facebook,office365,apple}— added under the existingauthroute group, behindThrottleRequestsmiddlewareAuthController::loginWith{Google,Facebook,Office365,Apple}+ sharedoauthRespondhelperFacebookVerifier, newOffice365Verifier; existingGoogleVerifierandAppleVerifierreused unchangedusers.microsoft_user_id(nullable + unique).User.\$fillableupdated. The other three columns (apple_user_id,facebook_user_id,google_user_id) already existedResponse shape on success matches the native
auth/loginendpoint exactly:{ token, type }.Account-linking semantics
The shared
oauthRespondhelper:Auth::register/ password-login behaviour).<provider>_user_idcolumn is null, stamps it (one-way link — never overwrites an existing different value).email_verified_at = now()since the IdP attested the email. No password set; account is OAuth-only until the user opts in to set one.twoFaSessionchallenge as password login (the issue's AC does not exempt OAuth from 2FA).Security notes
/debug_tokenauthenticated with the app token, then refuses ifis_valid != trueORapp_id != services.facebook.app_id. As a defence-in-depth, if the client supplied anappIdparameter, it must match the server's configuredapp_idtoo.storefront/server/src/Http/Controllers/v1/CustomerController.php::loginWithFacebook(line 581) acceptsfacebookUserIdfrom the request body without any server-side verification — anyone can POST a forged identifier. The verifier I added here closes that gap for the Console flow and is also a one-line backport to the storefront controller. Happy to open a separate PR for that if you'd like.AppleVerifier::verifyAppleJwtthrows on malformed JWT (unlike Google/Facebook/Office365 verifiers which return null on any failure). TheloginWithApplemethod wraps the call in try/catch so junk input becomes a clean 400 instead of an uncaught 500.Required config
The Google flow accepts
clientIdfrom the request body (matches the existing storefront pattern). Apple'sservices.apple.client_idis also read by the client side but is not required by the server-sideAppleVerifier.Dependencies
No new deps.
google/apiclientandlcobucci/jwtwere already incomposer.json.Test plan
php -lon all new and modified PHP filesphp artisan migrateruns cleanly;users.microsoft_user_idlands withvarchar(255) UNIQUEphp artisan route:list)errors[0]when posted a garbage tokenCompanion PR
Frontend UI:
fleetbase/fleetbase#TBD(will link as soon as opened) — adds four conditional Sign-in-with-X buttons toauth/login, lazy-loads each provider's JS SDK, posts the resulting credential to the endpoints in this PR.Refs: fleetbase/fleetbase#453