Skip to content

[google_sign_in] iOS incremental auth - Can't switch account and already granted scopes are not included #86660

Closed
flutter/plugins
#5708
@remideneleaodocs

Description

@remideneleaodocs

PR#2599 introduced the ability to request additional scopes after sign-in (incremental auth), allowing to request access to sensitive data only when needed and in the context where it makes sense to the user (cf. Requesting additional scopes on Android / on iOS).

While it works perfectly on Android, it is not really usable on iOS for 2 reasons:

  • You can't switch to another Google account without closing / reopening your app
    After granting additional scopes using the requestScopes() method for Account A, you can't sign out to switch to Account B without closing / reopening your app. Indeed if you call signOut() and then signIn() to select Account B, the account chooser is not displayed and Account A is automatically selected and used.
    It seems to be related to the way the additional permission request is implemented on iOS: it sets the loginHint of the GIDSignIn sharedInstance with the current user email before calling signIn(). But then, when calling signOut() the loginHint (and the scopes) of the sharedInstance are not cleared, so they are reused next time signIn() is called.

    The current requestScopes() method implementation corresponds to what was described in the the Google Identity documentation:

    image

    But the documentation was updated on July 13, advising to use the addScopes method instead:

    image

    The addScopes methods was introduced in the recent 6.0 release of GoogleSignIn iOS for which an issue (#86436) was opened a few days ago, to update the dependency. I don't know if this method will fix the issue but I hope so, at least it doesn't seem to modify a "shared instance" to do the additional permissions request.

  • Already granted scopes are not included at next sign in

    • Instantiate a GoogleSignIn() with minimal scopes, e.g. GoogleSignIn(scopes: ['email', 'profile']);
    • Later grant additional scopes, e.g. requestScopes(['https://www.googleapis.com/auth/drive.file']),
    • Then call signOut(),
    • Close your app,
    • Launch your app, which will instantiate a GoogleSignIn() with minimal scopes
    • Call signIn() and select your account

    You obtain an access token with only the email and profile scopes, so only the scopes declared when instantiating the GoogleSignIn() are requested. Already granted scopes are not included and there is no option to include them (like when using the include_granted_scopes option when doing Web sign-in), whereas on Android already granted scopes are included when you sign in back.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: google_sign_inThe Google Sign-In pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions