【问题标题】:Unable to retrieve agentUserId trough OAuth 2.0 Playground无法通过 OAuth 2.0 Playground 检索 agentUserId
【发布时间】:2019-11-21 15:39:21
【问题描述】:

按照以下网站上的说明进行操作时,我卡在第 2 步。

https://developers.google.com/assistant/smarthome/tools/smart-home-test-suite

点击“兑换令牌的授权码”后,我没有收到任何代码,而是出现401 Unauthorized 错误。

不知道在此测试期间出了什么问题,因为操作本身运行良好。

这是 OAuth 游乐场的输出:

Host: oauth.teletask.be 
Content-length: 169 
content-type: application/x-www-form-urlencoded 
user-agent: google-oauth-playground

code=XIspHj&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=***********&client_secret=************&scope=&grant_type=authorization_code

HTTP/1.1 401 Unauthorized 
X-xss-protection: 1; mode=block 
X-content-type-options: nosniff 
Transfer-encoding: chunked 
Expires: 0 
Www-authenticate: Basic realm="oauth2/client" 
Server: nginx/1.14.1 
Connection: keep-alive 
Pragma: no-cache 
Cache-control: no-cache, no-store, max-age=0, must-revalidate 
Date: Thu, 21 Nov 2019 14:59:59 GMT 
Strict-transport-security: max-age=31536000 ; includeSubDomains 
Content-type: application/json;charset=UTF-8 
X-frame-options: DENY

{
    "status": 401,
    "timestamp": "2019-11-21T14:59:59.599+0000",
    "message": "Unauthorized",
    "path": "/auth/oauth/token",
    "error": "Unauthorized" 
}

【问题讨论】:

    标签: google-smart-home oauth2-playground


    【解决方案1】:

    当您的 OAuth 服务器 (oauth.teletask.be) 接收到来自 Google 的授权代码授予时,该 401 错误正在生成,特别是您输入为 令牌端点 的端点。您应该检查您的服务器日志,以了解有关它拒绝请求的原因的更多详细信息。

    这里的常见问题包括拒绝redirect_uriclient_id,因为它们与预期值不匹配。也可能是您的授权码的生命周期太短,并且在您点击按钮以将其换成令牌之前,该代码已过期。

    【讨论】:

    • 添加了“redirect_uri”并确定,“client_id”也是正确的。 “access_token_validity”为 900 秒。但这可能不是授权码的过期时间。我想它没有设置,所以它不会过期?当我使用 Postman 获取新的访问令牌时,它工作正常,但是交换步骤是自动、直接完成的。
    • 来自 oauth-server 的日志:dropbox.com/s/1l450a6c7u8ffv5/…>
    • 授权码由您的服务器验证,因此由您的服务器逻辑来确定它接收到的代码是否有效。您的错误日志当前状态“访问被拒绝(用户是匿名的)”,这可能是相关的。
    猜你喜欢
    • 1970-01-01
    • 2016-02-19
    • 2021-03-07
    • 2020-04-11
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    相关资源
    最近更新 更多