每次登录时都获得新的GitHub访问令牌

时间:2018-03-12 17:25:16

标签: node.js github oauth-2.0 passport.js

我使用passport-github对GitHub进行身份验证,但每次用户登录时,访问令牌都会更新。这是预期的行为吗?

策略配置和快速路由:

passport.use(new GithubStrategy({
        clientID: process.env.IMPAKT_ID,
        clientSecret: process.env.IMPAKT_SECRET,
        callbackURL: process.env.IMPAKT_CALLBACK
    }, function(accessToken, refreshToken, profile, cb) {
        User.findOneAndUpdate({id: profile.id}, {accessToken, username: profile.username}, {upsert: true, new: true}, function(err, user) { // Update code, since access token changes.
            return cb(err, user);
        });
    }
));
app.get("/auth", passport.authenticate('github', {scope: ['public_repo']}));

app.get("/auth/callback", passport.authenticate('github', { failureRedirect: '/auth' }), function(req, res) {
    res.redirect('/');
});

0 个答案:

没有答案