2017-04-10 170 views
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應用程序,可以伸出援助之手,將不勝感激

回答

0

答案是在innitail路線時,要求它每一次創建的同意提示。

app.get('/auth/google', passport.authenticate('google',{accessType: 'offline', prompt: 'consent', scope: ['openid profile email https://www.googleapis.com/auth/drive']}))