Google oauth2.0重定向URI缺少哈希(#)和路径

发布于 2025-01-23 11:56:46 字数 825 浏览 3 评论 0原文

我正在使用Google API实现OAuth 2.0,但是Google的重定向URI缺少哈希(#)和路径。这导致我的解析失败。我正在为网络浏览器建造。

我向Google要求URI:
https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A4002%2Fsso-callback&response_type=token&state=C2ubRxTMwv&client_id=...

redirect_uri解码为http:// localhost:4002/sso-callback

Google的重定向URI:
http:// localhost:4002/state = c2ubrxtmwv& access_token = ...
这同时缺少/sso-callback路径和在使用response> response> response_type = token

google api api settings:

不确定这是配置问题还是Google问题。

I am implementing OAuth 2.0 with Google API's, but the redirect Uri from Google is missing the hash (#) and path. Which causes my parsing to fail. I am building for Web Browsers.

My Request URI to Google:
https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A4002%2Fsso-callback&response_type=token&state=C2ubRxTMwv&client_id=...

The redirect_uri decodes to http://localhost:4002/sso-callback

Google's Redirect URI:
http://localhost:4002/state=C2ubRxTMwv&access_token=...
Which is missing both the /sso-callback path and the # needed to distinguish the OAuth params when using response_type=token

Google API Settings:
Google Console Settings

Not sure if this is a config issue, or a Google issue.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看春风乍起 2025-01-30 11:56:46

当我通过将其粘贴到Chrome的地址栏中提交该URL时:

https://accounts.google.com/o/oauth2/auth?scope=https://mail.google.com/&response_type=token&client_id=111111-aaaaaaaa.apps.googleusercontent.com&state=1&redirect_uri=http://localhost:3000/callback

我收到一个注释的重定向

 http://localhost:3000/callback#state=1&access_token=ya29.A0ARrdaM-tPsT7jLIaCoVdhHo5vW71tYF1Z4ESfNNzNAh6SN7e_a4x24V0HVu4M427KF3bpWk8-Sm37oUxUHDpA-mMGJrAQPHgMlDA0suMVW2R0WBR_9vQiaPf8cMB8Tna8EH9wLSrm58PG3g30HJWUio1Ytyh&token_type=Bearer&expires_in=3599&scope=https://mail.google.com/

:Google Auth Server似乎仅使用Google Console中配置的第一个重定向URI。在您的情况下,它是

http://localhost:4002

尝试将所需的重定向URI放置

http://localhost:4002/sso-callback 

在控制台中的第一个位置。

When I submit this URL by pasting it in the address bar in Chrome:

https://accounts.google.com/o/oauth2/auth?scope=https://mail.google.com/&response_type=token&client_id=111111-aaaaaaaa.apps.googleusercontent.com&state=1&redirect_uri=http://localhost:3000/callback

I receive a redirect to

 http://localhost:3000/callback#state=1&access_token=ya29.A0ARrdaM-tPsT7jLIaCoVdhHo5vW71tYF1Z4ESfNNzNAh6SN7e_a4x24V0HVu4M427KF3bpWk8-Sm37oUxUHDpA-mMGJrAQPHgMlDA0suMVW2R0WBR_9vQiaPf8cMB8Tna8EH9wLSrm58PG3g30HJWUio1Ytyh&token_type=Bearer&expires_in=3599&scope=https://mail.google.com/

A few notes: Google auth server seems to only use the first redirect URI configured in Google Console. In your case it is

http://localhost:4002

Try placing your desired redirect URI

http://localhost:4002/sso-callback 

in the first position in the Console.

老街孤人 2025-01-30 11:56:46

事实证明,有一个SSR重定向正在打破我不知道的URL。 Delta George的答案让我尝试了其他一些URL,这使该问题清楚了。

Turns out there was an SSR redirect that was breaking the urls that I did not know about. The answer by Delta George got me to try out a few other urls which made the issue clear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文