Google登录服务器的身份验证代码是否没有iOS? [英] Google Sign in server auth code nil iOS?
问题描述
我们已经在应用程序中使用Google登录.在登录请求时,我们将提供serverClientID.
We have Google sign in our application.We are providing serverClientID at the time of request of login.
我们将user.serverAuthCode设置为nil.
We are getting user.serverAuthCode as 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
,如下所示:
We are trying to get the serverAuthCode
as follows :
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)")
}
}
但是它的serverAuthCode
为空,我们不确定可能出了什么问题.
But its serverAuthCode
is null we are not sure what may have gone wrong.
推荐答案
要注意的是,服务器身份验证代码仅在用户首次登录时才发送.用户必须已经看到了确认屏幕.在所有后续登录中,将不发送服务器身份验证代码.转到 https://security.google.com/settings/security/permissions 并删除您的应用程序的凭据,然后您将获得服务器身份验证代码.
The catch is that the server auth code will only be sent the first time the user logs in. The user must have just seen the confirmation screen. On all subsequent logins, no server auth code will be sent. Go to https://security.google.com/settings/security/permissions and removed the credentials for your app, then you'll get a server auth code.
这篇关于Google登录服务器的身份验证代码是否没有iOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!