返回令牌后,Google上的操作和帐户关联失败

时间:2017-03-30 09:22:18

标签: oauth oauth-2.0 google-oauth actions-on-google google-home

尝试使用OAuth2授权代码流https://developers.google.com/actions/tools/web-simulator

在Web模拟器中测试auth

请参阅:https://developers.google.com/actions/tools/testing#testing_account_linking_with_google_home_web_simulator

和: https://developers.google.com/actions/develop/identity/oauth2-code-flow

如果您已将行动设置为要求授权服务授权,当您尝试访问行动时,助理会建议您需要关联您的帐户。 在同一个响应中,模拟器提供了一个用于启动链接过程的URL,请参阅:

"debugInfo": {
    "sharedDebugInfo": [
        {
            "name": "Account Linking Url",
            "debugInfo": "https://assistant.google.com/services/auth/handoffs/auth/start?provider=your-google-project-id_dev&scopes=your-scopes&return_url=https://www.google.com/"
        }
    ]
}

调用此网址(粘贴到浏览器中)将引导您完成OAuth2流程,假设所需的用户操作成功,Google将使用流程中提供的授权代码调用您的令牌端点。

但后来我得到了:

result_code=FAILURE&result_message=Account+linking+failed

这一切似乎都在我这边工作,但谷歌正在返回失败。

1 个答案:

答案 0 :(得分:5)

就我而言,我的令牌端点正在返回我的标准令牌响应对象,其中包括 access_token refresh_token expires_in ,一个 session_state 和另一个为此目的不需要的令牌,但这是我的令牌响应的标准。

当我在Googles游乐场测试同样的响应时,它很好: https://developers.google.com/oauthplayground/

但使用智能助理网址时却不是这样: https://assistant.google.com/services/auth/handoffs/auth/start?provider=your-google-project-id_dev&scopes=your-scopes&return_url=https://www.google.com/

原因是助手不喜欢响应对象中的多余属性。

我还没有完全确定什么是允许的,但是到目前为止你可以拥有:

{
    "token_type": "Bearer",
    "access_token: "xxx",
    "refresh_token": "yyy",
    "expires_in": "zzz"
}

有了这些我现在得到:

result_code=SUCCESS