如何在iOS中设置与后端集成的Google登录?

huangapple go评论80阅读模式
英文:

How to set up iOS Google Sign In with backend integration?

问题

我正在尝试按照https://developers.google.com/identity/sign-in/ios/offline-access上的说明进行操作。每当我发送一个令牌时,我都会收到"redirect_uri_mismatch"的错误。

我在另一个问题中看到说客户端ID需要等待一段时间。但这并不是我的情况。后端ID从8月份开始就一直处于活动状态。Web应用程序正常工作。服务器的JSON文件将"redirect_uris"设置为"postmessage"。

这看起来与https://stackoverflow.com/questions/33877951/cross-platform-google-oauth-signin-redirect-uri-mismatch中的问题非常相似,但我的情况是在iOS和Go中。

如果我按照https://developers.google.com/identity/protocols/CrossClientAuth中的建议添加一个作用域"audience:server:client_id:<client_id>",我会收到"invalid scope"的错误。

英文:

I'm trying to follow the instructions at: https://developers.google.com/identity/sign-in/ios/offline-access. Whenever I send a token I get: "redirect_uri_mismatch".

I read in another question that client ids need to wait for a bit. This is not the case. The backend id has been active since August. The web app works fine. The server json sets "redirect_uris" to "postmessage".

This looks very similar to the question: https://stackoverflow.com/questions/33877951/cross-platform-google-oauth-signin-redirect-uri-mismatch but my scenario is with iOS and Go.

If I add a scope "audience:server:client_id:<client_id>" as suggested by https://developers.google.com/identity/protocols/CrossClientAuth I get an "invalid scope" error.

答案1

得分: 1

我找到了方法。

首先,忘记关于"audience:server:client_id:"的部分。

    let signin = GIDSignIn.sharedInstance()
    signin.clientID = "XXXX-YYYY.apps.googleusercontent.com"
    signin.serverClientID = "XXXX-ZZZZ.apps.googleusercontent.com"
    signin.scopes.append("https://www.googleapis.com/auth/plus.me")
    signin.delegate = self

其次,重定向网址并不重要。

最后,你需要注意的另一件事是serverAuthCode只会出现一次。所以,如果你支持注销,请确保使用GIDSignIn.sharedInstance().signOut

英文:

I found the way.

First, forget about "audience:server:client_id:".

    let signin = GIDSignIn.sharedInstance()
    signin.clientID = &quot;XXXX-YYYY.apps.googleusercontent.com&quot;
    signin.serverClientID = &quot;XXXX-ZZZZ.apps.googleusercontent.com&quot;
    signin.scopes.append(&quot;https://www.googleapis.com/auth/plus.me&quot;)
    signin.delegate = self

Second, redirect_uris don't matter.

Last, the only thing else that you need to be careful is that serverAuthCode will only come once. So be sure to GIDSignIn.sharedInstance().signOut if you support log out.

huangapple
  • 本文由 发表于 2016年10月26日 10:06:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/40252570.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定