oAuth JWT 导致无效参数错误 (400)

oAuth JWT resulting in Invalid Argument Error (400)

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

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

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

请求URL: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 发回 google 的 body(我猜这会导致上述错误):

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

body 的结构是否正确?我认为这是因为 jwt-token 但当我手动解码时一切看起来都很好。

感谢任何帮助!

谢谢

Unfortunately my linking fails in the last step. I think that I'm not returning the result of my /token endpoint correctly back to google.

请注意,您的 access/refresh 标记对 Google 是不透明的。您正在为 Google 移交这些凭据,以便在以后的请求中传回给您。这些标记的含义以及如何确定它们的有效性取决于您的 OAuth 服务器实现。

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

This is the body I send back to google for /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