Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用passport azure ad的多个策略_Node.js_Adal_Passport Azure Ad - Fatal编程技术网

Node.js 使用passport azure ad的多个策略

Node.js 使用passport azure ad的多个策略,node.js,adal,passport-azure-ad,Node.js,Adal,Passport Azure Ad,在同一个应用程序中是否可以有多个策略。 我有一个应用程序需要通过 通过App1(client1)或App2(client2) 当使用passport azure ad策略时,我总是只通过其中一个进行身份验证 以下是路线: app.get('/login1', passport.authenticate('azuread-openidconnect', { failureRedirect: '/' }), .... }); app.post('/auth/openid/return1'

在同一个应用程序中是否可以有多个策略。 我有一个应用程序需要通过 通过App1(client1)或App2(client2)

当使用passport azure ad策略时,我总是只通过其中一个进行身份验证

以下是路线:

app.get('/login1', 
  passport.authenticate('azuread-openidconnect', { failureRedirect: '/' }),
  ....
});

app.post('/auth/openid/return1',
  passport.authenticate('azuread-openidconnect', { failureRedirect: '/' }),
  function(req, res) { 
    ...
  });

app.get('/login2', 
  passport.authenticate('azuread-openidconnect', { failureRedirect: '/' }),
  ....
});

app.post('/auth/openid/return2',
  passport.authenticate('azuread-openidconnect', { failureRedirect: '/' }),
  function(req, res) { 
    ...
  });
以下是配置的策略

passport.use(new OIDCStrategy({
    clientID: config.creds.clientID1,
    redirectUrl: config.creds.redirectUrl1,
    clientSecret: config.creds.clientSecret1,
...
});


passport.use(new OIDCStrategy({
    clientID: config.creds.clientID2,
    redirectUrl: config.creds.redirectUrl2,
    clientSecret: config.creds.clientSecret2,
...
});
更新:passport-azure-ad不支持此操作。 通过深入调查来证实。当我们添加新策略时,实际上是在“azuread openidconnect”键上添加策略 当我们添加另一个时,它将覆盖现有的

passport._strategies['azuread-openidconnect']
尽管如此,它将始终使用最新的

对于我的场景,一个应用程序需要通过多个AAD应用程序进行身份验证,我们还有解决方案吗


目前的解决方案是:我们应该注册一个多租户AAD应用程序,并将租户限制在我们想要的范围内。

您可以创建两个策略并覆盖它们的名称,然后在passport.authenticate中指定策略。这个方法适合我

var strategy1 = new OIDCStrategy(...);
strategy1.name = "strategy1";

var strategy2 = new OIDCStrategy(...);
strategy2.name = "strategy2";

passport.use('strategy1');
passport.use('strategy2');

app.get('/login1', passport.authenticate('strategy1', ...));

app.post('/auth/openid/return1', passport.authenticate('strategy1', ...));

app.get('/login2', passport.authenticate('strategy2', ...));

app.post('/auth/openid/return2', passport.authenticate('strategy2', ...));

根据我的理解,注册一个多Azure广告应用程序是一个正确的解决方案。您是否有此解决方案无法满足的其他要求?