Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SignIn fails when serverClientID specified #51

Closed
DimGun opened this issue Aug 25, 2015 · 9 comments
Closed

SignIn fails when serverClientID specified #51

DimGun opened this issue Aug 25, 2015 · 9 comments

Comments

@DimGun
Copy link

DimGun commented Aug 25, 2015

Hi, guys! I've got a server that interacts with Google Calendar on behalf of user. To do this it should obtain one-time access token from iOS application. I've referred to documentation, but have some issues with sign in.

I started from "SignIn" example app (pod test Google > Sign In), provided it with my credentials (GoogleServices-Info.plist, bundleId). Then I signed it with my provision and started on iPhone 6, everything works like a charm.

Then I added

[GIDSignIn sharedInstance].serverClientID = @"<my-server-client-id>";

in ViewController:viewDidLoad. And then after opening auth screen (youtube.app, 10.31.11670), and selecting the same account, it launched my app (permissions screen is not presented), -signIn:didSignInForUser:withError: method was called, but GIDGoogleUser was nil. Error stated

Error Domain=com.google.GIDSignIn Code=-1 "A potentially recoverable error occured. You may try again." UserInfo=0x17026af80 {NSLocalizedDescription=A potentially recoverable error occured. You may try again.}

I tried several times, but each time I received the same result. But if I comment ...serverClientID... it begins to work again.

Then I launched this app in simulator and it authorised successfully using WebView and I received user.serverAuthCode.
I decided that problem was in YouTube.app, I uninstalled it from device, but the same problem happened with other Google applications.

Could you point me what is wrong with my singIn implementation?

PS
Finally I decided to use workaround and rewrote -canOpenUrl: in UIApplication subclass this way:

- (BOOL)canOpenURL:(NSURL *)url
{
    if ([[url scheme] hasPrefix:@"com-google-gidconsent"] || [[url scheme] hasPrefix:@"com.google.gppconsent"]) {
        return NO;
    }
    return [super canOpenURL:url];
}

And now it uses WebView authorisation and I can receive my one-time token. But it's a bit crappy of course.

@ianbarber
Copy link
Contributor

Just to check, what was the version of the YouTube app (or other Google app used for auth)? From reading your description it doesn't sound like you made a mistake, but for reference: did you put the serverClientID setting before or after the call to configureWithError

@DimGun
Copy link
Author

DimGun commented Sep 1, 2015

Hi @ianbarber, thanks for reply. In example provided in "pod test Google > Sign In" -[GGLContext configureWithError:] is called in -[AppDelegate application:didFinishLaunchingWithOptions:], I just added .serverClientID=... in ViewController. So it's definitely set after calling configureWithError.

It was YouTube app v10.31.11670. If I delete it from device, then my app uses WebView to authorise although I have Google Hangouts, Google Docs, Google Sheets, Google Drive on my device. Seems like these apps don't provide auth capability. And as I mentioned before, authorisation using WebView works just fine.

I even tried this app on another iPhone 6 and had the same results.

@mjgaylord
Copy link

I am experiencing the same issue. Auth works fine if I don't use a serverClientID, the problem is that I need this in order to retrieve a serverAuthCode for our server.

@DimGun
Copy link
Author

DimGun commented Sep 1, 2015

@mjgaylord As a temporary solution you can use subclass of UIApplication and rewrite it's canOpenUrl method (you can find it in my original message). Don't forget to put your UIApplications subclass name to Info.plist with NSPrincipalClass key.

@mjgaylord
Copy link

@DimGun Thanks! I will try that next. I am trying with a different bundle ID right as I saw in another issue that certain characters in bundle IDs might be causing the problem.

@DimGun
Copy link
Author

DimGun commented Sep 1, 2015

@mjgaylord My application bundleId contains only allowed characters [a-z.].

@mjgaylord
Copy link

Yeah, I can confirm that that bundle ID is not the issue. It's unfortunate that we need to use this hack, since it means that users need to go through the entire web login process in order to authenticate themselves in my app and if they have 2-factor auth enabled, it's even more friction for them.

@mjgaylord
Copy link

Just updated my pods to the latest version and this fix doesn't work any longer. There doesn't seem to be any way of preventing the SDK from opening a Google app as it doesn't inspect canOpenURL:.

@ianbarber
Copy link
Contributor

Tested this now with the current pod version and I'm seeing sign in happen in-app, its not switching to YouTube. I'll mark this as closed, but if anyone is seeing it on the latest pod, please reopen and include any pertinent details!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants