Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google User serverAuthCode nil in Objective-C

I'm trying to integrate the GoogleSignIn framework in an iOS app and also authenticate an user on a server. I managed to log in the user, but in the - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error delegate method, user.serverAuthCode is nil, and I need to pass this server authentication code to, uhm, authenticate the user on the server.

I read this documentation page and it states that I have to set the serverClientID property of the [GIDSignIn sharedInstance], but nowhere is it stated where do I find this "server client id". I ran tests with all the keys in the world to no avail.

I then found out this documentation page which looks like it's trying to tell us where to find this magical id, but it's using poor wording and didn't help. I do have OAuth2 credentials with type Web application, but:

  1. They are used for the web (client) app, that corresponds to my iOS app, which also communicates with the server
  2. I tried using it, and it didn't work.

Did anyone manage to successfully escape from the Google (poor) documentation's clutches?

like image 940
Iulian Onofrei Avatar asked Mar 01 '16 17:03

Iulian Onofrei


3 Answers

You need to make sure [GIDSignIn sharedInstance].serverClientID property is set; the value can be found in Google API Console.

Also, if you got user.serverAuthCode with nil value, make sure you called [[GIDSignIn sharedInstance] signOut]; before any subsequent attempts. Otherwise [GIDSignIn sharedInstance] seems to remember previous configuration.

I have no problem getting the serverAuthCode in the simulator.

like image 191
Alex Bin Zhao Avatar answered Nov 03 '22 14:11

Alex Bin Zhao


Try NOT running it in the simulator :)

like image 5
Iulian Onofrei Avatar answered Nov 03 '22 13:11

Iulian Onofrei


Had the same problem. GIDSignIn.sharedInstance().serverClientID is the same as GIDSignIn.sharedInstance().clientID. Solved by setting serverClientId too.

like image 3
Edoardo Vicoli Avatar answered Nov 03 '22 13:11

Edoardo Vicoli