restorePreviousSignIn()在GIDSignIn-iOS SDK V6.0.2到期时不获取新的idTo



我已经实现了谷歌签名流到我的iOS。第一次登录工作完美,但1小时后,当谷歌提供的idToken过期,restorePreviousSignIn()方法被调用,但返回相同的idToken。是否有人可以发布restorePreviousSignIn()方法的实现

我的restorePreviousSignIn()方法如下-

GIDSignIn.sharedInstance.restorePreviousSignIn { user, error in
if error != nil || user == nil {
print("Could not sign in user previously.nError: (String(describing: error))")
}
else {

}
}

试试这个:

GIDSignIn.sharedInstance.restorePreviousSignIn { user, error in
if error != nil || user == nil {
// Prompt the user to sign in again
GIDSignIn.sharedInstance.signIn()
} else {
if let auth = user.authentication {
if auth.accessTokenExpirationDate.timeIntervalSinceNow < 0 {
// Access token has expired, refresh the token
auth.refreshToken { refreshedAuth, error in
if error != nil || refreshedAuth == nil {
// Refresh failed, prompt the user to sign in again
GIDSignIn.sharedInstance.signIn()
} else {
// Refresh succeeded, update the user's authentication object
user.authentication = refreshedAuth
// Use the refreshed idToken to authenticate the user
// Your code here
}
}
} else {
// Access token is still valid, use the existing idToken to authenticate the user
// Your code here
}
} else {
// Prompt the user to sign in again
GIDSignIn.sharedInstance.signIn()
}
}
}

相关内容

  • 没有找到相关文章

最新更新