GIDSignIn specify scopes before prompt

1.5k Views Asked by At

I upgraded to GoogleSignIn 6.0 on iOS and I can not find a way to specify scopes for login at the time of signIn. All I can see is an API called addScopes() where I can specify scopes after basic signIn. But this results in two separate prompts for signIn which is weird. Earlier, we could simply specify scopes for signIn like this:

  signIn = GIDSignIn.sharedInstance()
  signIn.scopes = ["https://www.googleapis.com/auth/youtube.upload"]
  signIn.signIn(...)      

I wonder if there is any sample code for new GoogleSignIn 6.0? Even the sample code supplied by Google has two step sign in, first for general signin and then add scopes sign in.

2

There are 2 best solutions below

0
Ting Yi Shih On

Right now it's recommended to perform two-stage requests: sign in first, and then request permission for scopes.

GIDSignIn.sharedInstance.signIn(
    with: configuration,
    presenting: presenting,
    callback: { user, error in

        // If success
        print("Sign in successfully")

        GIDSignIn.sharedInstance.addScopes(
            ["YOUR_SCOPE"],
            presenting: presenting,
            callback: { user, error in

                // If success
                print("Scope requested successfully")

            }
        )

    }
)

Reference: https://github.com/google/GoogleSignIn-iOS/issues/23#issuecomment-880233289

0
Ben On

I think it’s useful to note that the addScopes method has been removed from GIDSignIn instance, and moved to GIDGoogleUser instead. Source: https://cocoapods.org/pods/GoogleSignIn/changelog