Googlesignin - Always Return "The User Canceled the Sign-In Flow." in iOS 11

How to fix `The user canceled the sign-in flow.` with Sign In with Google on iOS?

I also faced the issue before. The GIDSignInButton object don't need addTarget in code or linking @IBAction. The GIDSignInButton class already handle that action for us.

Signing in using FirebaseUI doesn't back out of webview and throws error

Ran into same problem from the Firecast videos, you need to add a call back in AppDelegate.swift

func application(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}

Reference https://firebase.google.com/docs/auth/ios/google-signin

Custom Google Sign-In button - iOS

You can add your own button instead of using Google Sign-In button
Do follwing things

Objective C Version

1)Add your own button into storyBoard

2)drag action into viewController

- (IBAction)googlePlusButtonTouchUpInside:(id)sender {
[GIDSignIn sharedInstance].delegate = self;
[GIDSignIn sharedInstance].uiDelegate = self;
[[GIDSignIn sharedInstance] signIn];
}

3)handle delegate methods

#pragma mark - Google SignIn Delegate

- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error {

}

// Present a view that prompts the user to sign in with Google

- (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController
{
[self presentViewController:viewController animated:YES completion:nil];
}

// Dismiss the "Sign in with Google" view

- (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];

}

//completed sign In

- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error {
//user signed in
//get user data in "user" (GIDGoogleUser object)
}

Swift 4 Version

In Swift make sure you have added briding header as the library is written in objective C

1)Add your own button into storyBoard

2)drag action into viewController

@IBAction func googlePlusButtonTouchUpInside(sender: AnyObject) {
GIDSignIn.sharedInstance().delegate=self
GIDSignIn.sharedInstance().uiDelegate=self
GIDSignIn.sharedInstance().signIn()
}

3)handle delegate methods

//MARK:Google SignIn Delegate

func signInWillDispatch(_ signIn: GIDSignIn!, error: Error!) {
}

// Present a view that prompts the user to sign in with Google

func signIn(_ signIn: GIDSignIn!,
presentViewController viewController: UIViewController!) {
self.present(viewController, animated: true, completion: nil)
}

// Dismiss the "Sign in with Google" view

func signIn(_ signIn: GIDSignIn!,
dismissViewController viewController: UIViewController!) {
self.dismiss(animated: true, completion: nil)
}

//completed sign In

   public func signIn(_ signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: Error!) {
if (error == nil) {
// Perform any operations on signed in user here.
let userId = user.userID // For client-side use only!
let idToken = user.authentication.idToken // Safe to send to the server
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
// ...
} else {
print("\(error.localized)")
}
}

Edit: Here is the reference/evidence for usage of custom button, Google Doc reference

In these examples, the view controller is a subclass of
UIViewController. If, in your project, the class that implements
GIDSignInUIDelegate is not a subclass of UIViewController, implement
the signInWillDispatch:error:, signIn:presentViewController:, and
signIn:dismissViewController: methods of the GIDSignInUIDelegate
protocol. Also don't forget to set UI delegate GIDSignIn.sharedInstance()?.uiDelegate = self

Google sign in failed com.google.android.gms.common.api.ApiException: 10:

Basically problem is in the SHA1 key put on console please regenerate it and put again properly same project.

1)As the answers, make sure that your actual signed Android apk has the same SHA1 fingerprint as what you specified in the console of your Firebase project's Android integration section (the page where you can download the google-services.json)

For more info, see: Generate SHA-1 for Flutter app

2)On top of that go to the Settings of your firebase project (gear icon right to the Overview at the top-left area. Then switch to Account Linking tab. On that tab link the Google Play to your project.

EDIT:
Account Linking tab doesn't exist any more, instead :

  1. Sign in to Firebase.
  2. Click the Settings icon, then select Project settings.
  3. Click the Integrations tab.
  4. On the Google Play card, click Link.

Sample Image



Related Topics



Leave a reply



Submit