使用PassPortJS和Node.jS获取谷歌OAuth 2.0刷新令牌
问题描述:
我无法通过Passport JS从Google获取刷新令牌。我一直在删除我帐户中的访问权限,以确保它是首次登录。我一直对令牌“未定义”。这是我目前的代码。使用PassPortJS和Node.jS获取谷歌OAuth 2.0刷新令牌
Passport.use(new GoogleStrategy({
clientID: "xxxxx.apps.googleusercontent.com",
clientSecret: "xxxxx",
callbackURL: `https://localhost:${port}/auth/google/callback`,
accessType: 'offline',
passReqToCallback: true
},
function(req,accessToken, refreshToken, profile, done) {
var tokens = {
access_token: accessToken,
refresh_token: refreshToken
}
console.log(tokens)
oauth2Client.setCredentials(tokens);
done(err = false, user = true)
}));
如果有人工作经验的OAuth到他们的Web应用程序,可以伸出援助之手,将不胜感激
答
答案是在innitail路线时,要求它每一次创建的同意提示。
app.get('/auth/google', passport.authenticate('google',{accessType: 'offline', prompt: 'consent', scope: ['openid profile email https://www.googleapis.com/auth/drive']}))