使用passport-azure-ad OIDCStrategy与Passportjs时遇到问题

我正在尝试使用passport-azure-ad来validation用户身份。 该应用程序显示常见的login屏幕,但当我login,浏览器窗口变为空白,并显示一个微调指示其工作。 与此同时,我的服务器正在接收连续的POST请求到我的callbackterminal。

在此期间,我的护照function(validation,serializeUser和deserializeUser)都不会被调用。

这里是我的战略定义:

passport.use("azure", new azureStrategy({ identityMetadata: 'https://login.microsoftonline.com/common/.well-known/openid-configuration', clientID: "*************************", responseType: 'code id_token', issuer: "https://sts.windows.net/********************/", responseMode: 'form_post', redirectUrl: "http://localhost:5055/auth/azure/callback", allowHttpForRedirectUrl: true, clientSecret: "**********************************" }, function(iss, sub, profile, accessToken, refreshToken, done) { console.log("ID TOken: ", profile.oid); //Never gets called console.log("User" ,profile) //Never gets called done(null, profile); })); passport.serializeUser(function(user, done){ console.log("serialize: ", user) //Never gets called done(null, user); }) passport.deserializeUser((user, done) => { console.log("deserialize: ", user) //never gets called done(null, user); }) 

这里是我的路线定义:

 app.get("/auth/azure", passport.authenticate('azure', {failureRedirect: '/'})) app.post("/auth/azure/callback", (req, res, next) => { console.log("POST Callback Received!"); next(); }, passport.authenticate("azure", { failureRedirect: "/error.html" }), (req, res) => { console.log("Recieved POST callback") res.redirect("/user") }) 

有几件事要提到:

  1. 我正在为我的组织开发应用程序,因此它只应validationAD中的用户。
  2. 我最初尝试使用https://login.microsoft.com/<tenant>...版本的identityMetadata,但我收到一个关于应用程序不支持的API版本的错误 – 使用通用似乎已经解决了这个问题。
  3. 正如我上面提到的,serializeUser,deserializeUser和validationcallback中的console.log()代码永远不会被调用。

我的nodejs服务器上的控制台窗口只是显示这个:

 Request at: 1477083649230 GET / {} Request at: 1477083649235 GET /login.html {} Request at: 1477084498737 GET /auth/azure {} Request at: 1477085275630 POST /auth/azure/callback {} POST Callback Received! Request at: 1477085275980 POST /auth/azure/callback {} POST Callback Received! Request at: 1477085276335 POST /auth/azure/callback {} POST Callback Received! Request at: 1477085276679 POST /auth/azure/callback {} POST Callback Received! Request at: 1477085277042 POST /auth/azure/callback {} POST Callback Received! 

你可以看到,直到我杀死该会话或浏览到网站上的其他页面。 还要注意,当POSTcallback日志被创build时,在authentication之后发生的日志从来不会这样做。

任何帮助将不胜感激。

使用Google身份validation策略时,我使用GET发回; 但是,当我遵循Azure示例时,我们开始使用POST进行回发。

我从我认为是不必要的样本中抽出了一切。 其中之一是bodyParser。 不幸的是,这是一个必要的部分,所以Passport可以parsingPOST请求的正文,以获得从auth服务器发回的信息。

所以,要求的位如下:

 var parser = require("body-parser") ... //before passport.initialize() app.use(parser.urlencoded({extended: true})); 

这一切都花了,一切都开始工作,因为它应该。 希望这节省了别人所有的头痛!