我正在使用Google Apps脚本创建Gmail插件的背景.通过这个插件,我想使用REST服务请求连接到我的后端服务器(非Google服务).该请求必须经过授权.授权后,我可以向该服务器发出请求,以接收与该数据库中该用户相关的数据.我已经在我的webapp中使用Google登录来登录后端服务 - 在前端,我在授权响应中收到了GoogleUser对象内部的id_token.
问题是
我需要这个id_token才能通过Gmail插件连接到我的后端服务.但是,我找不到如何访问令牌的方法.
我认为必须通过Apps脚本中的API提供令牌
的研究
.
在webapp中,我使用Google Auth API收到id_token,如下所示:
Promise.resolve(this.auth2.signIn())
.then((googleUser) => {
let user_token = googleUser.getAuthResponse().id_token; // this is the id_token I need in the Gmail plugin, too
// send the id_token to the backend service
...
};
Run Code Online (Sandbox Code Playgroud)
在Google Apps脚本API中,我只能找到OAuth令牌:
ScriptApp.getOAuthToken();
Run Code Online (Sandbox Code Playgroud)
我假设令牌也可以存储在会话中.Google Apps脚本API包含Session类,它本身包含getActiveUser方法,该方法返回User对象.但是,User对象仅包含用户的电子邮件地址,没有id令牌(或其他任何内容):
Session.getActiveUser().getEmail();
Run Code Online (Sandbox Code Playgroud)
问题
是否有办法获取身份令牌?
我是否选择使用Gmail中已登录用户的数据登录后端服务器的正确方法?
google-api google-openid google-apps-script google-oauth gmail-addons