我正在尝试为iOS实施Google登录,我按照https://firebase.google.com/docs/auth/ios/google-signin上提到的所有步骤设置Google登录,但是当我收到GIDSignInDelegate
回拨
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error
我将HTTP错误代码设置为400,用户对象为nil
,描述为
Error data:
{
error = "invalid_grant";
"error_description" = "verifier does not match.";
}
我的代码非常简单,只是实现了Google登录按钮,我的View控制器实现了GIDSignInDelegate。
演示代码:
In AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FIRApp configure];
[GIDSignIn sharedInstance].clientID = [FIRApp defaultApp].options.clientID;
PBLoginSignupUserViewController *loginSignupVC = [[PBLoginSignupUserViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:loginSignupVC];
self.window.rootViewController = navController;
return YES;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [[GIDSignIn sharedInstance] handleURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
In MyViewController.m <GIDSignInUIDelegate, GIDSignInDelegate>
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error {
// GETTING ERROR HERE, AND nil AS USER OBJECT
if(!error){
GIDAuthentication *authentication = user.authentication;
FIRAuthCredential *credential = [FIRGoogleAuthProvider credentialWithIDToken:authentication.idToken
accessToken:authentication.accessToken];
} else {
// show toast for error
}
}