Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Plus API GPPSignIn error code "Mismatched authentication"

I'm trying to add the GooglePlus API into my app.

I've added the Google+ framework using CocoaPods and I've got the sign in button in my app.

The GPPSignIn object is set up as follows in the viewDidLoad function in the view controller that does the signing in...

@property (nonatomic, strong) GPPSignIn *signIn;
...
self.signIn = [GPPSignIn sharedInstance];
self.signIn.clientID = @"blahblahmynumber.apps.googleusercontent.com";
self.signIn.scopes = @[kGTLAuthScopePlusLogin];
self.signIn.delegate = self;

[self.signIn trySilentAuthentication];

Then when the sign in button is pressed...

- (IBAction)googleButtonPressed:(id)sender
{
    [self.signIn authenticate];
}

... and the delegate method...

- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
                   error: (NSError *) error
{
    NSLog(@"Received error %@ and auth object %@",error, auth);
}

It all seems to work, I get pushed off to Google to sign in and confirm access to my account and then I get pushed back to the app and the console shows...

Received error Error Domain=com.google.GooglePlusPlatform Code=-1 "Mismatched authentication" UserInfo=0x1d5cb170 {NSLocalizedDescription=Mismatched authentication} and auth object (null)

Now I'm stuck. I can't find any information on what "Mismatched Authentication" means?

BTW, all the code I've written has come from the Google developer portal and "How to" docs.

Things I have attempted so far

  • Double and triple checked the ClientID and it is correct.
  • Changed the ClientID on Google and this stops the login completely so it is not this causing the problem.
  • Cleaned the project and the project folder.
  • Tried changing the scopes array to all possible combinations using kGTLAuthScopePlusLogin and kGTLAuthScopePlusMe.
  • Checked that my app on google is of Application Type "iOS" and it is.
  • Checked the URL Types on the app but this just stops the app being pushed back after login.
  • This is definitely NOT a redirect_uri_mismatch problem. The problem is "Mismatched Authentication" returned to the sign in delegate after signing in.
like image 728
Fogmeister Avatar asked Dec 07 '22 06:12

Fogmeister


1 Answers

OK, fix for this was easy. Delete some code.

I followed the Google Docs on how to create a sign in screen to the letter.

I added the GPPSignInButton and attached it to a function to run [signIn authenticate].

However, this is where I went wrong. The GPPSignInButton has this function built in. Somehow, by making it run exactly the same function it was causing this error to appear.

The fix was simple. Just delete the action on the button. The button will look like it has no function but it actually works as the sign in button properly.

In the docs it says to use [self.signIn authenticate]; to start the sign in process. It doesn't say that if you use the GPPSignInButton that it does this automagically. Grr :( Anyway, I've now fixed it by removing the code to sign in...

Hope this helps someone.

like image 64
Fogmeister Avatar answered Dec 10 '22 11:12

Fogmeister