"redirect_uri_mismatch" error registering iOS Client for OAuth2.0

224 views
Skip to first unread message

Innovation Lab

unread,
Sep 7, 2015, 5:35:19 AM9/7/15
to Google App Engine
Hi All,

I am trying to use OAuth2.0 authentication in iOS client. 
For this, I have created one clientID for iOS app in Google Developer Consol. This generated the ClientID and iOS redirect URI.

With the help of GTMOAuth2ViewControllerTouch, I am trying to get access token of the User. Below is the code:-

GTMOAuth2ViewControllerTouch *viewController;

        viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:scope

                                                                    clientID:kMyClientID

                                                                clientSecret:kMyClientSecret

                                                            keychainItemName:kKeychainItemName

                                                                    delegate:self

                                                            finishedSelector:@selector(viewController:finishedWithAuth:error:)];

        

        [self presentModalViewController:viewController

                                animated:YES];


- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController

      finishedWithAuth:(GTMOAuth2Authentication *)auth

                 error:(NSError *)error {

    [self dismissModalViewControllerAnimated:YES];

    

    if (error != nil) {

        // Authentication failed

        NSLog(@"error description%@",error.description);

        

    } else {

        // Authentication succeeded

        signedIn = true;

        [[self domainService] setAuthorizer:auth];

         auth.authorizationTokenKey = @"id_token";

         NSLog(@"\n accessToken value is %@",auth.accessToken);

        [self showEnterPinDialogue:auth.userEmail isConfirmEnable:true];

    }

}  

Now, I am getting error during signin process is "redirect_uri_mismatch". 

After this, I generated new ClientID with category "Others App" . This step results in the generation of ClientID and ClientSecret. Now I had used this ClientID in the project and google Sign In is successful. 


Please explain me, Why clientID for Ios client not worked but for "others" its working.

Nick (Cloud Platform Support)

unread,
Sep 8, 2015, 12:53:17 PM9/8/15
to Google App Engine
Hey Innovation Lab,

Generally, a specific question like this would be better suited to stackoverflow. This forum is meant for more general discussion of the platform, and you'll find many more users on stackoverflow who are ready and willing to help you. Nonetheless I'll see if I can help you here.

How did you generate the iOS Client ID? What was the format of the redirect uri? It seems as though you should have no trouble using the iOS Client ID if all fields are properly filled-out and you followed all steps in the docs. Of course if you did that and the issue occurred, we'd have diagnosed an issue, but we need to make sure everything is done properly first in order to know if that's the case. 

Your source code sort-of looks like the code in the Endpoints docs - are you attempting to auth to an Endpoints API? It also could be related to the code shown in the Drive API docs, which shows a generic Google API OAuth2 flow for iOS. Did you follow those docs? 

Let me know where you started, and I'll see if I have any advice. 

Best wishes,

Nick
Reply all
Reply to author
Forward
0 new messages