Description
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 therequestScopes()
method for Account A, you can't sign out to switch to Account B without closing / reopening your app. Indeed if you callsignOut()
and thensignIn()
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 theloginHint
of theGIDSignIn sharedInstance
with the current user email before callingsignIn()
. But then, when callingsignOut()
theloginHint
(and thescopes
) of thesharedInstance
are not cleared, so they are reused next timesignIn()
is called.The current
requestScopes()
method implementation corresponds to what was described in the the Google Identity documentation:But the documentation was updated on July 13, advising to use the
addScopes
method instead: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
andprofile
scopes, so only the scopes declared when instantiating theGoogleSignIn()
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. - Instantiate a