google-api - 如何在服务器端扩展在客户端获得的 Google OAuth 令牌
问题描述
我有一个基于 EmberJS 构建的前端和 Java 后端的 Web 应用程序。
我让用户使用 Google OAuth 登录并请求范围:https://www.googleapis.com/auth/calendar
{
"El": "google_user_id",
"Zi": {
"token_type": "Bearer",
"access_token": "access_token",
"scope": "openid email profile https://www.googleapis.com/auth/calendar.readonly https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/calendar",
"login_hint": "login_hint",
"expires_in": 3600,
"id_token": "..AF16AF6oc7Fl2uv5V9r",
"session_state": {
"extraQueryParams": {
"authuser": "0"
}
},
"first_issued_at": 1550770587899,
"expires_at": 1550774187899,
"idpId": "google"
},
"w3": {
"Eea": "google_user_id",
"ig": "Shivang Tripathi",
"ofa": "Shivang",
"wea": "Tripathi",
"Paa": "https://mnsbfsdbf/photo.jpg",
"U3": "shivang.tripathi@org.com"
}
}
现在,我将此响应发送到服务器。服务器可以使用提供的“access_token”通过使用 REST 进行 API 调用来执行各种任务,例如获取日历列表等。例如。使用“access_token”作为授权标头调用https://www.googleapis.com/calendar/v3/users/me/calendarList 。
不过我遇到了一个问题。令牌是短暂的,会在 60 分钟内过期。
我可以以某种方式将此令牌扩展到永无止境的令牌或长寿令牌吗?Facebook 允许这样做:https ://developers.facebook.com/docs/facebook-login/access-tokens/refreshing 有人可以告诉我谷歌是否允许从服务器端这样做以及如何?
解决方案
说“没有其他办法”是不正确的。正确的方法是再次发出auth请求,但添加“prompt=none”。顺便说一句,“login_prompt”应该是电子邮件地址或 Google 用户 ID。
推荐阅读
- javascript - 如何制作一个按钮,按下时按钮会消失并弹出一个新的div
- python - vs代码终端说python 2.7,但我选择了3.8
- command - 如何从Stata的数据集中删除特定的观察结果?
- r - 如何使 klaR 的 greedy.wilks 函数在后 HCPC 数据帧上工作?
- javascript - 背景图像不适用于 Chrome for Mac 上的一个 div
- docker-compose - Docker-compose 按项目名称隔离网络
- swift - 在 TabView 中无法识别 editMode 更改
- android - Android:退出应用程序,要求第二次点击或忽略?
- java - Java Springboot 反应式存储库 - myReactiveRepository.insert(myMono) 和 myMono.flatmap(myRepository::save) 之间的区别
- java - 有没有办法将 jar 文件转换为可以独立运行的可执行文件(在 Windows 上)?