我正在尝试使用 passport-github 策略对用户进行身份验证。似乎一切正常,除了我无法在回调中获取个人资料信息。但是能够在serializeUser函数中获取该信息。
var configurePassport = {
configureGithubStrategy : (app) => {
// STEP 1 : [Initialize passport into the app]
app.use(passport.initialize())
app.use(passport.session());
// STEP 2 : [Implement serialize and deserialize objects of passport]
passport.serializeUser(function(profile,done){
console.log(`+++ Inside Serialize +++\n${profile.username}\n+++ Note : Able The Get Profile Information +++`)
done(null,profile);
})
passport.deserializeUser(function(profile,done){
done(null,profile);
})
// STEP 3 : [Configure GitHub Strategy]
passport.use(new GitHubStrategy({
clientID: config.gitHub.clientID,
clientSecret: config.gitHub.clientSecret,
callbackURL: config.gitHub.callbackURL
},
function(accessToken, refreshToken, profile, done) {
console.log(`+++ Inside Configuration +++\n${profile}`)
done(null,profile)
}
));
}
}
const passport = require('passport')
const configurePassport = require('./config/passportConfig')
configurePassport.configureGithubStrategy(app)
app.get('/auth/github',passport.authenticate('github'));
app.get('/auth/github/callback',passport.authenticate('github',{failureRedirect : '/auth/failed'}),function(request,response){
console.log(`Unable To Get Profile Information -> ${request.profile}`)
response.redirect('/profile')
})
app.get('/profile',function(request,response){
response.status(200).json(request.profile)
})
内部回调函数request.profile 变得不受约束