如何使用oauth2client(Google-auth-library)获得Google Workspace附加应用程序的刷新
我有一个使用Node.js构建的Google Workspace附加应用程序,并具有以下范围:
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/calendar.addons.execute",
"https://www.googleapis.com/auth/gmail.readonly"
当提示用户接受范围时,我将获得包含的令牌列表;
userOAuthToken, systemIdToken, userIdToken
这里的问题是,授予的用户是有时的,因此我需要一个刷新令牌才能访问以备后用。我正在尝试访问刷新令牌,但会遇到错误:
错误:未设置刷新令牌。在oauth2client.refreshtokennocache错误。
我正在使用以下代码访问刷新令牌,
const accessToken = req.body.authorizationEventObject.userOAuthToken;
const auth = new OAuth2Client();
auth.setCredentials({access_token: accessToken});
auth.refreshAccessToken().then((token)=>{
console.log("token is " + token);
}).catch((err)=>{
console.log(err);
});
该如何解决此错误?
I have a Google Workspace add-on application built with Node.js with the following scopes:
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/calendar.addons.execute",
"https://www.googleapis.com/auth/gmail.readonly"
When the user gets prompted to accept scopes, I will get a list of tokens included;
userOAuthToken, systemIdToken, userIdToken
The issue here is that the userOAuthToken granted is time-bound, so I need a refresh token to access for later use. I am trying to access refresh token but getting an error:
Error: No refresh token is set. at OAuth2Client.refreshTokenNoCache error.
I am using the following code to access the refresh token
const accessToken = req.body.authorizationEventObject.userOAuthToken;
const auth = new OAuth2Client();
auth.setCredentials({access_token: accessToken});
auth.refreshAccessToken().then((token)=>{
console.log("token is " + token);
}).catch((err)=>{
console.log(err);
});
How can I fix this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论