fix: handle unregistered account on Google/social sign-in#492
Conversation
The mobile access-token exchange endpoint (AUTH_ENTRY_LOGIN_API) only signs
in an already existing/linked account; a first-time or unlinked social
identity returns invalid_grant. The Sign In screen previously surfaced this
as a generic "Something went wrong". It now shows a specific
"This <method> account is not linked with any <platform> account. Please
register." message (matching iOS), guiding new users to the
Register -> Continue with Google flow that creates and links the account.
Also fix the Google OAuth scope requested in GoogleAuthHelper: it was a
malformed, email-only string ("oauth2: .../userinfo.email") and is now
"oauth2:openid .../userinfo.email .../userinfo.profile", matching the
iOS/web clients and the server-side google-oauth2 DEFAULT_SCOPE.
|
Thanks for the pull request, @PavloNetrebchuk! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Problem
Signing in with Google (or another social provider) from the Sign In screen fails with a generic "Something went wrong" whenever the Google identity has no corresponding account on the platform.
Under the hood, the mobile token-exchange endpoint
POST /oauth2/exchange_access_token/{provider}/runs the social-auth pipeline withAUTH_ENTRY_LOGIN_API, which only signs in an already existing / linked account (associate-by-email). A first-time or unlinked social identity therefore returns:{"error": "invalid_grant", "error_description": "access_token is not valid"}even though the provider resolves the user's details. This matches the community report: Android app Google SSO invalid_grant.
Changes
SignInViewModel— distinguishEdxError.InvalidGrantExceptionon social login and show a specific, actionable message instead of the generic error:This mirrors the iOS app and guides new users to the existing Register → Continue with Google flow, which creates and links the account. Other social-login failures still fall through to the generic error.
GoogleAuthHelper— fix the requested Google OAuth scope. It was a malformed, email-only string ("oauth2: …/userinfo.email", note the stray space) and is now:aligning with the iOS/web clients and the server-side
google-oauth2DEFAULT_SCOPE(["openid", "email", "profile"]).New string
auth_social_account_not_registered.Testing
Verified end-to-end on an emulator against a local Tutor Open edX with real Google OAuth clients:
invalid_grant→ the new "not linked… please register" message is shown (previously: generic error).200creates + links the account, the exchange then returns200, and the user lands on the dashboard.200)../gradlew detektAll :auth:testDevelopDebugUnitTestpasses.