如何使用refreshAccessToken方法在google-api-nodejs-client中生成新的accesstoken [英] how to use the refreshAccessToken method to generate a new accesstoken in google-api-nodejs-client

查看:205
本文介绍了如何使用refreshAccessToken方法在google-api-nodejs-client中生成新的accesstoken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现此拉取请求会在使用保存的刷新令牌刷新访问令牌。我不清楚如何使用它。我已经从原始getToken请求中保存了令牌(包括刷新令牌),并且现在正在新会话中从数据库检索令牌。如何在OAuth2Client上设置凭据,以便我可以调用refreshAccessToken并获取新的accesstoken?解析方案

我已经错过了< https://github.com/google/google-api-nodejs-client#making-authenticated-requestsrel =noreferrer>关于在github自述文件中设置证书的段落,所以这里是一些示例代码,以防其他人需要它。

  var googleOauth2Client =新的OAuth2Client(googleClientId,googleClientSecret,googleCallbackUrl); 
googleOauth2Client.setCredentials({
refresh_token:saved_refresh_token
});
googleOauth2Client.refreshAccessToken(function(err,tokens){
response.send({
access_token:tokens.access_token
});
});


I see that this pull request adds a method to refresh the access token using a saved refresh token. It is not clear to me how to use it. I have saved the tokens (including the refresh token) from the original getToken request and am now retrieving the token from the Database in a new session. How do I set the credentials on OAuth2Client so that I can call refreshAccessToken and get a new accesstoken?

解决方案

I had missed the paragraph on setting credentials on the github readme, so here is some sample code in case anybody else needs it.

var googleOauth2Client = new OAuth2Client(googleClientId,googleClientSecret, googleCallbackUrl);
googleOauth2Client.setCredentials({
  refresh_token: saved_refresh_token
});
googleOauth2Client.refreshAccessToken(function(err, tokens){
  response.send({
    access_token: tokens.access_token
  });
});

这篇关于如何使用refreshAccessToken方法在google-api-nodejs-client中生成新的accesstoken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆