"Accounts failed to link" 当我尝试在我的 Web 服务上授权 Google 助手时发生错误

"Accounts failed to link" error happens when I try to authorize Google Assistant at my Web service

首先,我想提一下,以前在以下主题中讨论过这样的问题:

但我找不到任何与使用我自己的网络服务器 linking Google 助手应用程序相关的信息。

问题:

获取https://oauth-redirect.googleusercontent.com/r/my-google-assistant-app#access_token=ACCESS_TOKEN&token_type=bearer&state=STATE always returns "Account field to link" error

重现方式:

  1. 我在 Google 控制台上的操作中创建了一个新项目
  2. 我使用 Dialogflow 构建了一个应用程序
  3. 我创建了一个 Heroku Web 服务器作为我的 webhook(例如:webhook.herokuapp.com)

所以一切正常。我已成功将我的 Google 智能助理应用程序与我的网络钩子连接起来。

但后来我决定将请求发送到我的另一个需要用户登录的 Heroku Web 服务器(例如:webserver.herokuapp.com)。所以我决定使用 webserver.herokuapp.com

实现我的 Google 助手应用程序的帐户 linking
  1. 我在 webserver.herokuapp.com 实现了 Google-OAuth2 授权。另外我想提一下,我使用了 Google Assistant App
  2. 的 Client ID 和 Client Secret

因此,Google 授权在我的 网络服务器 上完美运行。herokuapp.com

  1. 然后我使用隐式流
  2. 为我的 Google 助手应用程序启用帐户 linking 设置

所以,就是这样!

结语

我打开 Google 助手,告诉它 "Talk to my test app",然后它向我打招呼并向我提供 link 帐户。我说 "yes"。 然后我看到 Google 助理如何在 webserver.herokuapp.com 请求我的登录 URL。然后我输入我的 Google 电子邮件和密码。结果我登录了我的网络服务器!然后我的网络服务器重定向到:

https://oauth-redirect.googleusercontent.com/r/my-google-assistant-app#access_token=ACCESS_TOKEN&token_type=bearer&state=STATE

我得到了我在 post.

顶部描述的错误

如有任何帮助,我们将不胜感激


UPDATE 带参数信息

These are my constants:
Google Assistant Project_ID = nodejs-sdk-local-test
Google Assistant Client_ID = 1067979601708-ldr3ga115es3fdo823slfnj46gjoes66.apps.googleusercontent.com
state = manually_set_state_value

流程是我打开 Google 助手并说 "Ok Google, talk to my test app",它回答了我的请求,然后我说了类似 "do some action which need authorization" 的内容。 Google 助理应用向我提供了 link 一个帐户,我说 "Yes"。

最常见的原因是您没有传回在 Google 重定向到您的站点时发送给您的 state 的相同值。请确保这是相同的值,并且为了您的安全,请确保您也验证了发送给您的其他参数。

当用户被重定向到 https://webserver.herokuapp.com/google-oauth2 时,应该有一些参数作为查询的一部分发送。这些参数包括一个 state 参数。它应该看起来像这样:

https://myservice.example.com/auth?client_id=GOOGLE_CLIENT_ID&redirect_uri=REDIRECT_URI&state=STATE_STRING&response_type=token

请注意,虽然 client_idredirect_uri 是您应该预期和测试的值,但 state 而不是 你会设置。 Google 每次生成一个不同的。这是您稍后重定向到

时应该使用的 state
https://oauth-redirect.googleusercontent.com/r/nodejs-sdk-local-test#access_token=<token_omitted>&token_type=bearer&state=STATE_STRING