谷歌登录iOS-获得新的ServerAuthCode

谷歌登录iOS-获得新的ServerAuthCode,ios,authentication,oauth-2.0,google-signin,Ios,Authentication,Oauth 2.0,Google Signin,我在iOS上登录我的用户,如下所示: [GIDSignIn sharedInstance].clientID = kGoogleClientID; // From services.plist [GIDSignIn sharedInstance].serverClientID = kGoogleServerID; // from api console, web application // those two are not needed for the auth code [GIDSign

我在iOS上登录我的用户,如下所示:

[GIDSignIn sharedInstance].clientID = kGoogleClientID; // From services.plist
[GIDSignIn sharedInstance].serverClientID = kGoogleServerID; // from api console, web application

// those two are not needed for the auth code
[GIDSignIn sharedInstance].shouldFetchBasicProfile = YES;
[GIDSignIn sharedInstance].scopes = @[@"email", @"profile"];

[GIDSignIn sharedInstance].delegate = self;

[[GIDSignIn sharedInstance] signIn]
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
     withError:(NSError *)error {

    // Perform any operations on signed in user here
    if (nil == error)
    {

        NSLog(@"Google Server Auth Code:%@", user.serverAuthCode);
    }
}
登录屏幕出现且用户登录后,我可以获得如下serverAuthCode:

[GIDSignIn sharedInstance].clientID = kGoogleClientID; // From services.plist
[GIDSignIn sharedInstance].serverClientID = kGoogleServerID; // from api console, web application

// those two are not needed for the auth code
[GIDSignIn sharedInstance].shouldFetchBasicProfile = YES;
[GIDSignIn sharedInstance].scopes = @[@"email", @"profile"];

[GIDSignIn sharedInstance].delegate = self;

[[GIDSignIn sharedInstance] signIn]
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
     withError:(NSError *)error {

    // Perform any operations on signed in user here
    if (nil == error)
    {

        NSLog(@"Google Server Auth Code:%@", user.serverAuthCode);
    }
}
这在第一次使用时效果很好,但是如果用户重新启动应用程序并再次登录谷歌,登录屏幕就不需要再次出现——因为用户已经知道了。因此,signIn立即成功,但没有新的自动代码。此外,有时我们可能需要另一个serverAuthCode在服务器上执行另一次登录,但不想用另一个登录屏幕打扰用户


如何为已经登录的用户获取新的serverAuthCode?

我对iOS版的.NET Google SignIn SDK也有同样的问题

这似乎与

在一条评论中,有人建议在调用
sign
之前立即调用
signOut


它为我解决了这个问题(使用.NETSDK),希望它也能为你解决。但它会强制用户重新连接。

同意。就我而言,我只需要获取此令牌一次,然后使用刷新令牌,因此这是一个可接受的解决方案,但如果它不符合您的需要,我可以理解。这是一个变通办法,而不是一个解决方案。但我们可以肯定的是,这是SDK中的一个bug,可能不会根据需要进行修复