Google oauth2抛出“ redirect_uri_mismatch”甚至对于确切的匹配即使是错误

发布于 2025-01-27 00:54:07 字数 1311 浏览 2 评论 0原文

我的应用程序已经适用于OAuth2隐式流。我正在尝试使其用于授权代码流,但遇到了“ redirect_uri_mismatch”的错误。我不明白的一部分是“ redirect_uri”实际上与API控制台中指定的内容完全匹配。这是我运行的curl命令,其中代码是通过google.accounts.oauth2.initcodeclient以弹出模式获得的。

curl -X POST https://oauth2.googleapis.com/token \
      --data-urlencode "code=${code}" \
      --data-urlencode "redirect_uri=https://localhost:3000/api/gcode" \
      --data-urlencode "client_id=${cid}" \
      --data-urlencode "client_secret=${cs}"  \
      --data-urlencode "grant_type=authorization_code"

这给了我一个错误:

{
  "error": "redirect_uri_mismatch",
  "error_description": "Bad Request"
}

redirect_uri与API控制台中指定的URI完全匹配: “快照”

我想念什么?我已经检查了一些旧帖子,例如 /a>,但这些解决方案都不适合我的情况。

更新: 该问题似乎与该弹出式UX模式的工作方式不同于与重定向UX模式不同。 so so 也报告了同样的问题。

My app already work for OAuth2 implicit flow. I am trying to make it work for authorized code flow but I encountered an error of "redirect_uri_mismatch". The part I don't understand is that the "redirect_uri" in fact matches exactly what is specified in the API console. Here is the curl command I ran, where the code is obtained via google.accounts.oauth2.initCodeClient with popup mode.

curl -X POST https://oauth2.googleapis.com/token \
      --data-urlencode "code=${code}" \
      --data-urlencode "redirect_uri=https://localhost:3000/api/gcode" \
      --data-urlencode "client_id=${cid}" \
      --data-urlencode "client_secret=${cs}"  \
      --data-urlencode "grant_type=authorization_code"

which gives me an error:

{
  "error": "redirect_uri_mismatch",
  "error_description": "Bad Request"
}

The redirect_uri matches exactly one of the specified uri in the API console: snapshot.

What did I miss? I have already checked some old posts such as this one but none of the solutions works for my case.

Update:
The problem seem to be related to that popup ux mode works differently than the redirect ux mode. This SO reports the same problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文