【问题标题】:oAuth JWT resulting in Invalid Argument Error (400)oAuth JWT 导致无效参数错误 (400)
【发布时间】:2020-10-08 14:34:55
【问题描述】:

我正在尝试使用 oAuth2 代码授权流程在我的 google 操作上启用帐户链接。

不幸的是,我的链接在最后一步失败了。我认为我没有将 /token 端点的结果正确返回给谷歌。

重定向到我的操作页面后,我可以在控制台中看到 400 错误的响应(/authorize 工作正常):

请求网址:https://oauthintegrations.clients6.google.com/v1/token:getForService?key=api-key-removed-by-me&alt=json

{
  "error": {
    "code": 400,
    "message": "\u003ceye3 title='/OpenIdConsumerService.ValidateOpenId, INVALID_ARGUMENT'/\u003e APPLICATION_ERROR;apps_auth/OpenIdConsumerService.ValidateOpenId;com.google.identity.accountlinking.error.FederatedProtocolException: \u003ceye3 title='INVALID_ARGUMENT'/\u003e OpenAuth::INPUT_ERROR: ;AppErrorCode=13;StartTimeMs=1602166359350;tcp;Deadline(sec)=59.962523136;ResFormat=UNCOMPRESSED;Originator=traffic-prod;Tag=\u0002cloud_project_number\u0003744920882961\u0002IncomingMethod\u0003/OAuthIntegrationsService.GetTokenForService\u0002cidc\u00032;ServerTimeSec=1.00669508;LogBytes=256;Non-FailFast;EffSecLevel=privacy_and_integrity;ReqFormat=UNCOMPRESSED;ReqID=2d3a46fa4ab8370e;GlobalID=c34268105821e185;Server=[2002:ab3:7310::]:4155",
    "status": "INVALID_ARGUMENT"
  }
}

这是我为 /token 发回谷歌的正文(我猜这会导致上面的错误):

{
"access_token":"jwt-token-here",
"expires_in":"1602162256000",
"refresh_token":"refresh-token-here",
"refresh_token_expires_in":"31535999",
"token_type":"Bearer",
"scope":"read"
}

身体的结构是否正确?我认为这是因为 jwt 令牌,但是当我手动解码时,一切看起来都很好。

任何帮助表示赞赏!

谢谢

【问题讨论】:

    标签: google-cloud-platform oauth-2.0 google-oauth actions-on-google


    【解决方案1】:

    不幸的是,我的链接在最后一步失败了。我认为我没有将 /token 端点的结果正确返回给谷歌。

    请注意,您的访问/刷新令牌对 Google 是不透明的。您将这些凭据移交给 Google,以便在以后的请求中传回给您。这些令牌的含义以及如何确定它们是有效的,取决于您的 OAuth 服务器实现。

    有关详细信息,请参阅OAuth account linking guide

    这是我为 /token 发回谷歌的正文

    scoperefresh_token_expires_in 字段不是 Google 在您的令牌交换响应中期望的参数,因此这很可能是 INVALID_ARGUMENT 错误的来源。对 Google 的基本令牌响应应如下所示:

    {
      "access_token":"jwt-token-here",
      "expires_in":"1602162256000",
      "token_type":"Bearer",
    }
    

    expires_in 字段指的是访问令牌以及 Google 何时应该使用刷新令牌来请求新的访问令牌

    如果您想使刷新令牌过期或轮换,您也可以这样做。但是,您无法告诉 Google 刷新令牌何时“过期”。要轮换刷新令牌,您必须在下次 Google 请求新的访问令牌时传回新令牌,例如:

    {
      "access_token":"jwt-token-here",
      "expires_in":"1602162256000",
      "refresh_token":"updated-refresh-token-here",
      "token_type":"Bearer",
    }
    

    有关请求和响应中的字段的更多详细信息,请参阅OAuth implementation guide

    【讨论】:

    • 谢谢,确实是expires_in参数的问题。
    猜你喜欢
    • 2015-11-28
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    • 2017-09-05
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    相关资源
    最近更新 更多