Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIDSignIn.sharedInstance.restorePreviousSignIn is not working as expected #346

Open
darkForestCat opened this issue Nov 2, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@darkForestCat
Copy link

Describe the bug

I've been using 'GoogleSignIn' version '4.1.1' for many years and didn't have any trouble.Recently I've updated to '7.0.0' because the older version does not support the Apple Silicon.Back on the '4.1.1' I've been using GIDSignIn.sharedInstance().signInSilently() to sign in the user that is already signed in.Then in the delegate method I was catching any kind of error.One of these errors is expired token.And on the older version everything was working perfect as a swiss watch while the newest version seems to have some troubles with catching errors on time.If I use '4.1.1' and I force sign out a Google account session with an app using this library everything works perfect, the delegate method handles immediately an error after the first GIDSignIn.sharedInstance().signInSilently() attempt, while the newest version where I'm forced to use this method:

GIDSignIn.sharedInstance.restorePreviousSignIn { user, error in    
            if error != nil || user == nil {
                self.service.authorizer = nil
            } else {
                self.service.authorizer = user?.fetcherAuthorizer
            }
 }

does not catch any kind of error and returns user without error as if everything is okay and no force sign out was done which leads to a bad user experience because app acts like if user is signed in, while actually not.The most interesting part is that after about 1 hour this method starts returning error saying "expired token", but again after waiting one hour.Does this method really supposed to give me an error about expired token after one hour and if so how to detect this error immediately without waiting so much time?

To Reproduce
Steps to reproduce the behavior:

  1. Sign in inside your app.
  2. Force sign out your app session from Devices section in the Security tab of your Google account settings.
  3. Restart the app, the app will act like the token is not expired, unable to show you any kind of data.
  4. Wait 1 hour but don't push Sign Out button in the app, just wait, after 1 hour restorePreviousSignIn method will return the error so the app will act like it should.
    Even the test app has this issue, if you will sign out like in the step 2 and you will restart the test app it will show you that you are signed in...

Expected behavior
I guess giving me the error immediately like the sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) method does in the version '4.1.1' without giving to a user any kind of bad experience.

Environment

  • Device: [ iPhone XS Max]
  • OS: [iOS 17.0 ]
  • Pod version: [ 7.0.0]
1) 2) 3) 4)
@darkForestCat darkForestCat added bug Something isn't working triage Issues that need to be triaged labels Nov 2, 2023
@mdmathias mdmathias removed the triage Issues that need to be triaged label Nov 8, 2023
@camden-king
Copy link
Contributor

Hello,

Thank you for reporting this.

restorePreviousSignIn seems to be working correctly. restorePreviousSignIn restores a locally cached user so it does not send any server requests if the tokens haven't expired (less than an hour old).

When you force a sign out from Google Accounts you are invalidating the token on the server but the client doesn't know until it requests new tokens.

This is different from signInSilently that was used until version 5. signInSilently fetched new tokens every time it was called.

I have switched this bug to an enhancement for a method that refreshes the tokens every time. Additionally we should update the doc comment for restorePreviousSignIn to be explicit that this method will return what was cached locally if the tokens haven’t expired.

@camden-king camden-king added enhancement New feature or request and removed bug Something isn't working labels Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants