Skip to content

fix: handle unregistered account on Google/social sign-in#492

Merged
volodymyr-chekyrta merged 1 commit into
openedx:developfrom
raccoongang:fix/google-sso-invalid-grant
Jul 21, 2026
Merged

fix: handle unregistered account on Google/social sign-in#492
volodymyr-chekyrta merged 1 commit into
openedx:developfrom
raccoongang:fix/google-sso-invalid-grant

Conversation

@PavloNetrebchuk

Copy link
Copy Markdown
Contributor

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 with AUTH_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

  1. SignInViewModel — distinguish EdxError.InvalidGrantException on social login and show a specific, actionable message instead of the generic error:

    This Google account is not linked with any OpenEdX account. Please register.

    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.

  2. GoogleAuthHelper — fix the requested Google OAuth scope. It was a malformed, email-only string ("oauth2: …/userinfo.email", note the stray space) and is now:

    oauth2:openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile
    

    aligning with the iOS/web clients and the server-side google-oauth2 DEFAULT_SCOPE (["openid", "email", "profile"]).

  3. 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:

  • Unregistered Google account: Sign In → Google → exchange returns invalid_grant → the new "not linked… please register" message is shown (previously: generic error).
  • Register → Continue with Google: the form is pre-filled with the Google name/email, registration 200 creates + links the account, the exchange then returns 200, and the user lands on the dashboard.
  • Existing/linked account: Sign In → Google signs in directly (200).
  • ./gradlew detektAll :auth:testDevelopDebugUnitTest passes.

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.
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jul 21, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @PavloNetrebchuk!

This repository is currently maintained by @openedx/openedx-mobile-maintainers.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@volodymyr-chekyrta volodymyr-chekyrta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

@volodymyr-chekyrta
volodymyr-chekyrta merged commit b3b2edc into openedx:develop Jul 21, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in Contributions Jul 21, 2026
@volodymyr-chekyrta
volodymyr-chekyrta deleted the fix/google-sso-invalid-grant branch July 21, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants