我们让 Google 登录您的应用程序。我们在请求登录时提供服务器客户端 ID。
我们得到的 user.serverAuthCode 为 nil。
我们的要求如下:
func googleLogin(){
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
let gid = GIDSignIn.sharedInstance()
if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist") {
let myDict = NSDictionary(contentsOfFile: path)
gid?.serverClientID = "our servers cliet id as configured over firebase"
// This client id of our ios app we are getting from
// GoogleService-info.plist
gid?.clientID = myDict!.value(forKey: "CLIENT_ID") as! String
}
// gid?.serverClientID = "our_servers" // TODO: fetch from plist
gid?.scopes.append("https://www.googleapis.com/auth/gmail.readonly")
print("\nClient Id: \(gid!.clientID!) Server Client Id: \(gid!.serverClientID!)\n")
gid?.delegate = self
}
我们正在努力获得serverAuthCode
如下 :
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if (error == nil) {
// Perform any operations on signed in user here.
let auth = user.serverAuthCode
print(auth)
let fullName = user.profile.name
} else {
print("\(error.localizedDescription)")
}
}
But its serverAuthCode
为 null 我们不确定可能出了什么问题。
问题是服务器验证码只会在用户第一次登录时发送。用户必须刚刚看到确认屏幕。在所有后续登录中,不会发送服务器验证代码。去https://security.google.com/settings/security/permissions https://security.google.com/settings/security/permissions并删除您的应用程序的凭据,然后您将获得服务器身份验证代码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)