首页 > 解决方案 > 如何在服务器端扩展在客户端获得的 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 有人可以告诉我谷歌是否允许从服务器端这样做以及如何?

标签: google-apigoogle-calendar-apigoogle-oauth

解决方案


说“没有其他办法”是不正确的。正确的方法是再次发出auth请求,但添加“prompt=none”。顺便说一句,“login_prompt”应该是电子邮件地址或 Google 用户 ID。


推荐阅读