Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google multiple login using GIDSignin

I can do authentication for single account using GIDSignIn by below code.

    GIDSignIn *googleSignIn = [GIDSignIn sharedInstance];
    googleSignIn.delegate = self;
    googleSignIn.uiDelegate = self;
    googleSignIn.clientID = (NSString*)cGmailAppClientId;
    googleSignIn.scopes = [self getGmailAuthenticationScopes];;
    [googleSignIn signIn];

But GIDSignIn is shared instance. It is for an only one account. How can I add multiple accounts? Multiple accounts should accessible concurrently (Ex getting access token).

Related SO question doesn't give correct idea.

like image 813
Mani Avatar asked Sep 04 '15 08:09

Mani


1 Answers

I don't think GIDSignIn supports multiple accounts. While in theory you could instantiate instances other than the sharedInstance, only one authorization will be persisted to the iOS keychain at a time. (The library would need multiple keys to save multiple authorizations, but if you instantiated multiple instances, how could it know which was which after a cold launch?)

Fortunately, there's Google's GTMAppAuth, an alternative library that fulfills the same purpose. It's a bit more complicated to use than GIDSignIn, but works in generally the same fashion. The key differentiators are that 1) you can create multiple authorizations at a time, and 2) you can persist them to the iOS keychain with keys of your choosing. If you're interested specifically in accessing Gmail, then these steps from the popular MailCore2 library may be helpful.

It sounds from this thread like the libraries are supported by different teams within the company, but I suspect it will be a while before they converge, if ever.

like image 84
lehrblogger Avatar answered Oct 19 '22 18:10

lehrblogger