17

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.

Mani
  • 17,549
  • 13
  • 79
  • 100
  • You cannot do that with GIDSignIn, you probably should do that by yourself by performing an HTTP requests. But google engineers are not that simple and you'll definitely face with anti-spam trouble. Why do you need a multiple accounts simultaneously on a single personal device? – Sega-Zero Sep 07 '15 at 07:18
  • People who have account for personal and office.(nowadays most of them, having two accounts is normal. right?). That's why. How do you say, "Cann't do with GIDSignIn?"... Is there any docs or atleast an forum question related with this? if yes, please post a link.. – Mani Sep 07 '15 at 08:24
  • My guess is also like your thought(`sharedInstance`). I know, that we can do switch concept for this. But my requirement is, I've to have account for all. Any way thank you for your thought (`sharedInstance`). – Mani Sep 07 '15 at 09:21
  • My experience on `GIDSignIn` shows, that token info stored in the keychain and you're unable to set a different token yourself, since `GIDSignIn` reads from keychain itself, so your task is probably impossible with ios sdk by google. – Sega-Zero Sep 07 '15 at 09:23
  • Did you try with two different `GIDSignIn ---> signIn`?(ie our own object instead of singleton object) It will save two token in keychain. but problem is how can we retrieve that two tokens if `GIDSignIn` object get destroyed? – Mani Sep 07 '15 at 09:52
  • No, I used singleton, I had no need in user switching, but had issues when user wanted to change google account and sometimes I had [that](http://stackoverflow.com/questions/26094598/unable-to-sign-in-into-google-from-the-googleplussample-code-using-googlepluspla) issue – Sega-Zero Sep 07 '15 at 09:58
  • I'm not using Sign-In button. If you use sign-in button, it will use `sharedInstance` only. There's no way to multiple with Sign-In button. – Mani Sep 07 '15 at 10:10
  • I used `GPPSignIn` which is quite equal to `GIDSignIn` on behavior – Sega-Zero Sep 07 '15 at 10:13

2 Answers2

5

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.

lehrblogger
  • 191
  • 2
  • 5
0

I managed to solve this by manually overriding the internal keychain (GTMKeychain) used by the library. I saved all the data values for key "auth" for all emails, restore them one by one inside GTMKeychain, then called restorePreviousSignIn which uses the value from GTMKeychain.

At the moment of writing, this solution works, but it's not guaranteed to work with future versions.