0

我正在尝试使用 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 变得不受约束

4

1 回答 1

0

纠正我如果我错了,但是我发现done()函数将请求对象上的配置文件信息附加为用户,因此它可以在回调 url 上作为request.user

于 2019-06-20T13:20:10.877 回答