我使用 Swift 3 允许用户登录我的应用程序,该应用程序使用 Parse-Server 后端。我可以很好地使用 Google Plus 登录,但是当我将 authData 发送到 Parse Server 以对用户进行 token 验证时出现错误,我收到一般错误“Google 身份验证对此用户无效”。我怀疑我在 loginWithType 方法中发送了错误的“id”。我检查了 Parse-Server 存储库中的代码,它只有“id”和“token”作为参数。我怀疑我发送了错误的“id”。所以 id 需要正确的信息作为 id 参数发送,并仔细检查我的格式。以下是我正在使用的代码。
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
print("google sign in hit in app delegate")
if (error == nil) {
print("error is not nil")
var curUser = PFUser.current()
if (curUser != nil)
{
print("Skip Google Auth - Found cur user");
return;
} else {
// 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
let idt = user.serverAuthCode
PFUser.register(AuthDelegate(), forAuthType: "google")
PFUser.logInWithAuthType(inBackground: "google", authData: ["id":user.authentication.clientID,"token":idToken!])
// logging in confirmed on back end
}
}
}
感谢您提供的任何帮助。
最佳答案
尝试改变
authData: ["id":user.authentication.clientID,"token":idToken!]
到:
authData: ["id":userId!,"token":idToken!]
关于ios - 使用 Swift 3 和 iOS 在发送到 Parse Server 的 authdata 对象中使用来自 google 登录的 authdata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42876364/