Javascript Azure Idendity平台重定向到主页,确保授权失败

Javascript Azure Idendity平台重定向到主页,确保授权失败,javascript,node.js,mongodb,connect-mongo,azure-identity,Javascript,Node.js,Mongodb,Connect Mongo,Azure Identity,我正在尝试为我的(相当简单的)CRUD应用程序实现一个身份验证步骤。因此,这就是想法:当连接到localhost:8000/时,您需要单击登录按钮,这将提示您使用Microsoft帐户登录。然后应该将您重定向到localhost:8000/feed。但它只是将我重定向到localhost:8000。第二个问题是,我可以看到MongoDB存储了一个Cookie。如果我访问localhost:8000/auth/logout,它会删除它。所以它起作用了。但我仍然无法访问localhost:8000/

我正在尝试为我的(相当简单的)CRUD应用程序实现一个身份验证步骤。因此,这就是想法:当连接到localhost:8000/时,您需要单击登录按钮,这将提示您使用Microsoft帐户登录。然后应该将您重定向到localhost:8000/feed。但它只是将我重定向到localhost:8000。第二个问题是,我可以看到MongoDB存储了一个Cookie。如果我访问localhost:8000/auth/logout,它会删除它。所以它起作用了。但我仍然无法访问localhost:8000/feed,因为ensureAuth不允许我访问

确保身份验证:

module.exports = {
ensureAuth: function(req, res, next){
    console.log("Executing ensureAuth function")
    if(req.isAuthenticated()){
        console.log("Is authenticated")
        return next()
    }else{
        console.log("ensureAuth failed")
        res.redirect("/")
    }
},
ensureGuest: function(req, res, next){
    if(!req.isAuthenticated()){
        return next()
    }else{
        res.redirect("/feed")
    }
}
}

身份验证/登录路径:

router.get('/login',
function(req, res, next) {
    passport.authenticate('azuread-openidconnect', 
      { 
        response: res,                      
        resourceURL: config.resourceURL,    
        customState: 'my_state',            
        failureRedirect: '/' 
      }
    )(req, res, next);
  },
  function(req, res) {
    console.log('Login was called in the Sample');
    res.redirect('/feed');
});
验证/注销路径:

router.get('/logout', function(req, res){
  req.session.destroy(function(err) {
    req.logOut();
    res.redirect(config.destroySessionUrl);
  });
});
进料路线:

const express = require("express")
const router = express.Router()
const feedController = require("../controllers/feed")
const { ensureAuth, ensureGuest } = require("../middleware/auth")

router.get("/", ensureAuth, feedController.getContent)

router.post("/postScream", feedController.postScream)

module.exports = router
特快会议:

app.use(
    session({
      secret: 'foo',
      resave: false,
      saveUninitialized: false,
      store: new MongoStore({ mongooseConnection: mongoose.connection }),
  })
)
如果你需要一段代码,打电话给我。我将感谢任何形式的支持