Skip to content

[google_sign_in_ios] handle restorePreviousSignIn invalid grant exception#11349

Open
felangel wants to merge 3 commits intoflutter:mainfrom
felangel:fix/google-sign-in-ios-invalid-grant
Open

[google_sign_in_ios] handle restorePreviousSignIn invalid grant exception#11349
felangel wants to merge 3 commits intoflutter:mainfrom
felangel:fix/google-sign-in-ios-invalid-grant

Conversation

@felangel
Copy link
Contributor

@felangel felangel commented Mar 25, 2026

Description

Adds exception handling to _getAuthorizationTokens to handle PlatformExceptions thrown by restorePreviousSignIn. This fixes a bug that would cause authorizeServer to throw a PlatformException due to an expired or revoked token.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the google_sign_in_ios package by adding error handling for restorePreviousSignIn() calls. It now includes a try-catch block to manage exceptions, specifically when tokens are expired or revoked, and attempts a new sign-in in such cases. A corresponding test has been added to validate this new behavior. Feedback suggests refining the exception handling to catch PlatformException instead of a general Exception for better error specificity.

@felangel felangel requested a review from stuartmorgan-g March 25, 2026 17:15
@felangel felangel changed the title [google_sign_in_ios] handle restorePreviousSignIn invalid_grant PlatformException [google_sign_in_ios] handle restorePreviousSignIn invalid grant exception Mar 25, 2026
@felangel felangel closed this Mar 25, 2026
@felangel felangel reopened this Mar 25, 2026
@fluttergithubbot
Copy link

An existing Git SHA, e2ec0c189a9f32f56fb9ee7a81a4e374b7ed9c4c, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

if (userId == null) {
SignInResult result = await _api.restorePreviousSignIn();
SignInResult result;
try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The intended design of this plugin is that we catch errors on the native side, where we still have full context. What exactly is throwing here? Is this throwing instead of calling the completion handler?

If so, we should catch it there, inspect the error, and turn this specific one into a known error value, and anything else into an unknown error, via the error return system used by all the other native code in this plugin. (We should also file an issue upstream if that's the case, since that would be surprising behavior.)

Copy link
Contributor Author

@felangel felangel Mar 25, 2026

Choose a reason for hiding this comment

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

The intended design of this plugin is that we catch errors on the native side, where we still have full context. What exactly is throwing here? Is this throwing instead of calling the completion handler?

I believe that is correct 👍

If so, we should catch it there, inspect the error, and turn this specific one into a known error value, and anything else into an unknown error, via the error return system used by all the other native code in this plugin.

Okay I can try to spend some time on that later this week. Feel free to take this over if you get to it before me.

We should also file an issue upstream if that's the case, since that would be surprising behavior.

Where exactly should this issue be filed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Where exactly should this issue be filed?

If the Google Sign In SDK is throwing an exception instead of calling the callback, that should be filed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[google_sign_in_ios] restorePreviousSignIn can throw PlatformException due to invalid grant

3 participants