Google User serverAuthCode nil in Objective-C

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

I am reading this documentation page and it claims that I need to set the serverClientID property for [GIDSignIn sharedInstance] , but nowhere is indicated where I can find this "server client identifier". I conducted tests with all the keys in the world to no avail.

Then I found out this documentation page , which looks like it is trying to tell us where to find this magic identifier, but with poorly worded language it didn't help. I have OAuth2 credentials with type Web application , but:

  • They are used for a web application (client) that matches my iOS application, which also communicates with the server
  • I tried to use it and it did not work.

Has anyone managed to successfully escape from the Google documentation clusters (poor)?

+5
source share
6 answers

Try NOT to run it in the simulator :)

+6
source

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

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

I have no problem getting serverAuthCode in the simulator.

+3
source

You can find client_id in plist, and server_client_id you can find through the API console manager.

You must first uninstall the application, then try again, the simulator or device, it will work.

+1
source

Use this configuration to get serverAuthCode , which is not nil :

 NSError *configureError; [[GGLContext sharedInstance] configureWithError:&configureError]; NSAssert(!configureError, @"Error configuring Google services: %@", configureError); [GIDSignIn sharedInstance].clientID = @"88.....apps.googleusercontent.com"; [GIDSignIn sharedInstance].serverClientID = @"88.....apps.googleusercontent.com" ; [GIDSignIn sharedInstance].shouldFetchBasicProfile = YES; [GIDSignIn sharedInstance].scopes = @[@"email", @"profile"]; 

Where:

  • clientID uses the REVERSED_CLIENT_ID value from GoogleService-Info.plist .
  • serverClientID uses the corresponding value from the Google Console .
+1
source

There was the same problem. GIDSignIn.sharedInstance().serverClientID same as GIDSignIn.sharedInstance().clientID . It was also decided to install serverClientId .

+1
source

Instead, get the access token from user :

 NNString* accessToken = user.authentication.accessToken; 
0
source

Source: https://habr.com/ru/post/1244239/


All Articles