Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Google+ Login and OAuth2 in Backend

Looking the tutorial of using Google+ SDK for iOS in this link, I am able to configure the project and grant my application to obtain an access token. However, I do not want to consume the token in the device to obtain its name, email, etc. I want to obtain a temporal access code (that can be changed for an OAuth2 token) or a id token as I do in my Android application. This is called by google the cross-client identity.

The idea is that the backend server will received this exchange code and will generate the access token to fetch the user profile, email, etc. Then the user is registered with this information. However the access token being generated by the iOS app can be only consumed by the application itself, since the application id used is the id of the iOS application. I have tried to change application id with the server application id, but then it is thrown a redirect_uri_mismatch.

Trying to consume the access token directly in the server will provoke a Google_OAuth_Exception, as the server client id is not equal to the application client id.

I have another approach running based on opening a web page, but I wanted to use the native Google+ login process.

Any idea?

like image 750
Alvaro Luis Bustamante Avatar asked Jan 17 '14 14:01

Alvaro Luis Bustamante


2 Answers

We are working on this feature. This will allow the application to get a "code" that you can send to your server to store offline access.

Sorry you'll have to wait a couple of weeks (sorry don't have an exact date).

like image 116
nvnagr Avatar answered Nov 01 '22 19:11

nvnagr


Naveen's answer is correct, but if you just need basic profile information and email address you can use the id token instead. This will include the email address (as long as you requested the email scope), and the user ID which can be used to query for public profile information from the Google+ API, without needing to pass a code or access token. Retrieving the ID token is really easy

[GPPSignIn sharedInstance] setHomeServerClientID:@"911581857976.apps.googleusercontent.com"];

- (void) finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error {
  if (error) {
    NSLog(@"Error: %@", error);
    return;
  }
  NSLog(@"ID Token: %@", [[GPPSignIn sharedInstance] idToken]);
}

I wrote up a longer example in a blog post a while back, which might help: http://www.riskcompletefailure.com/2013/11/client-server-authentication-with-id.html

like image 41
Ian Barber Avatar answered Nov 01 '22 19:11

Ian Barber