首页 > 解决方案 > 如何使用 OAuth 2 实现静默登录并从 google 获取代码/令牌

问题描述

我是谷歌誓言的新手,

参考google的文档

当我生成登录 URL 示例时

https://accounts.google.com/o/oauth2/auth?
redirect_uri=http://www.mywebapp.com/oauth2callback&
response_type=code&
client_id=104608secret-secret-secret-secret.apps.googleusercontent.com&
scope=https://www.googleapis.com/auth/analytics.readonly+https://www.googleapis.com/auth/userinfo.email&
approval_prompt=force&
access_type=offline

将重定向到显示谷歌电子邮件 ID的接受页面

当用户点击“接受”时,谷歌会将用户重定向到您给定的redirect_url

当我使用 chrome 和 https://developers.google.com/oauthplayground/ 因为它重定向屏幕接受。一切都会好起来的。

但是当我使用邮递员时,它不会返回谷歌的“访问码”

我在 url 参数中做错了什么。

我必须使用上面的 url 创建休息服务。

我已经搜索了 如何获取虚拟谷歌访问令牌来测试 oauth google api? 如何验证 Google 身份验证 API 访问令牌? https://developers.google.com/identity/protocols/OAuth2 https://www.themarketingtechnologist.co/google-oauth-2-enable-your-application-to-access-data-from-a-google-user /

但是没有解释关于静默登录以获取令牌而不接受屏幕

标签: restoauth-2.0postman

解决方案


您的回调 url 收到一个“代码”。

然后你需要用你的“代码”换取访问令牌。

https://aaronparecki.com/oauth-2-simplified/

https://developers.google.com/oauthplayground/

https://developers.google.com/identity/protocols/oauth2


推荐阅读