标签: passport-azure-ad

带有不记名策略的passport-azure-ad veriy msal.js 令牌

我试图将 msal.js 库(https://github.com/AzureAD/microsoft-authentication-library-for-js)与passport-azure-ad(https://github.com/AzureAD/passport-azure- ad ) 承载策略。

我的配置如下:Msal.js

{
    authority: 'https://login.microsoftonline.com/<tennant>',
    clientID: '<clientId>',
    graphScopes: ['user.read', 'Group.Read.All'],
};
Run Code Online (Sandbox Code Playgroud)

护照-天蓝色广告

const config = {
    identityMetadata: 'https://login.microsoftonline.com/<tennant>/v2.0/.well-known/openid-configuration',

    clientID: '<clientId>',

    validateIssuer: false,

    passReqToCallback: false,

    issuer: 'https://login.microsoftonline.com/<tennant>/v2.0',

    audience: '<clientId>',

    allowMultiAudiencesInToken: false,

    loggingLevel:'info',
    loggingNoPII: false,
};
Run Code Online (Sandbox Code Playgroud)

在前端,我通过登录流程和 auire 令牌使用

const token = await this.userAgentApplication.acquireTokenSilent(applicationConfig.graphScopes);
Run Code Online (Sandbox Code Playgroud)

然后我向受passport-azure-ad Bearer Strategy保护的端点发出请求并得到

authentication failed due to: In Strategy.prototype.jwtVerify: cannot verify token
Run Code Online (Sandbox Code Playgroud)

我也登录了图书馆,它说:

Error: invalid signature
Run Code Online (Sandbox Code Playgroud)

我的解码令牌如下所示:

{ header:
   { typ: 'JWT',
     nonce:
      'AQABAAAAAACEfexXxjamQb3OeGQ4GugvOOGFjNwsJMp-y1sPJ254AB4C4gW4sb4kOObzC5BvMpBM-89S8Ri5UvHxPIjpp9ZW408ZgJKLzb2hRWXkib2b7yAA',
     alg: 'RS256',
     x5t: '-sxMJMLCIDWMTPvZyJ6tx-CDxw0',
     kid: '-sxMJMLCIDWMTPvZyJ6tx-CDxw0' …
Run Code Online (Sandbox Code Playgroud)

node.js adal azure-ad-msal passport-azure-ad

7
推荐指数
1
解决办法
2328
查看次数

Passport azure-ad验证未调用回调

使用护照(带有“ passport-azure-ad”策略)对请求进行身份验证时遇到问题。对Azure Active Directory的请求运行正常。我可以使用自己的凭据登录。之后,我希望调用verify回调,根据accessToken等设置用户对象。然后,我希望在用户对象可用的地方调用重定向路由功能。这是我的设置:

passport.serializeUser((accessToken, done) => {
    done(null, accessToken);
});

passport.deserializeUser((accessToken, done) => {
    done(null, accessToken);
});

passport.use(new OIDCStrategy({
    // options for the azure AD strategy
    identityMetadata: config.auth.identityMetadata,
    clientID: config.auth.clientID,
    clientSecret: config.auth.clientSecret,
    redirectUrl: config.auth.redirectUrl,
    responseType: 'code id_token',
    responseMode: 'query',
    allowHttpForRedirectUrl: config.auth.allowHttpForRedirectUrl,
    isB2C: true,
    passReqToCallback: false,
    scope: config.auth.scope,
    loggingLevel: 'error'
}, (iss, sub, profile, jwtClaims, accessToken, refreshToken, params, done) => {
    console.log('1. VERIFY CALLBACK');
    if (!accessToken) {
        return done(new Error('No accessToken was given'), null);
    }
    return done(null, { accessToken, expires: …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express passport.js passport-azure-ad

5
推荐指数
1
解决办法
280
查看次数

每个用户使用 Nodejs-Restify-Passport 进行一个会话

如何使用 node-passport-restify 允许每个用户进行一个活动会话?IE; 不允许用户同时使用其他选项卡或浏览器在多个会话中处于活动状态。

这是运行应用程序的代码。

const
restify = require('restify'),
restifyPlugins = require('restify').plugins,
passport = require('passport'),
BearerStrategy = require('passport-azure-ad').BearerStrategy,
config = require('./config'),
authenticatedUserTokens = [],
serverPort = process.env.PORT || config.serverPort;

const authenticationStrategy = new BearerStrategy(config.credentials, (token, done) => {

let currentUser = null;
let userToken = authenticatedUserTokens.find((user) => {
    currentUser = user;
    user.sub === token.sub;
});

if (!userToken) {
    authenticatedUserTokens.push(token);
}

return done(null, currentUser, token);
});

passport.use(authenticationStrategy);

const server = restify.createServer({
name: 'My App'
});


server.use(restifyPlugins.acceptParser(server.acceptable));
server.use(restifyPlugins.queryParser());
server.use(restifyPlugins.fullResponse());
server.use(restifyPlugins.bodyParser({
  maxBodySize: 0, …
Run Code Online (Sandbox Code Playgroud)

node.js restify adal passport.js passport-azure-ad

5
推荐指数
0
解决办法
136
查看次数

在 azure 中设置 showPii

I\xe2\x80\x99m 配置我的 Passport/express/node azure 应用服务网站以进行单租户 azure 广告登录。我可以在本地主机上成功登录,但是当我发布网站时,我得到{"code":400,"message":"IDX10205: Issuer validation failed. Issuer: \'[PII is hidden]\'. Did not match: validationParameters.ValidIssuer: \'[PII is hidden]\' or validationParameters.ValidIssuers: \'[PII is hidden]\'."}

\n\n

我想我需要在某处设置 showPII 才能查看该 PII 并诊断/解决问题。我们如何在Azure节点中控制这个标志?

\n

azure azure-active-directory passport.js azure-web-app-service passport-azure-ad

5
推荐指数
0
解决办法
946
查看次数

使用passport-azure-ad 的OIDCStrategy 的多项策略

我们可以在同一个应用程序中为 OIDCStrategy 设置多个策略吗?我有一个应用程序需要通过 App1(ClientID1) 或 App2(ClientId2) 进行身份验证。

使用passport-azure-ad OIDCStrategy 时,我总是只通过其中之一进行身份验证。

以下是路线:

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) { 
    ...
  });
Run Code Online (Sandbox Code Playgroud)

这是配置的策略。

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,
...
});
Run Code Online (Sandbox Code Playgroud)

更新:passport-azure-ad 不支持此功能。通过深入验证。当我们添加新策略时,实际上是将策略添加到键“azuread-openidconnect” 当我们添加另一个策略时,它会覆盖现有的策略。

passport._strategies['azuread-openidconnect']
Run Code Online (Sandbox Code Playgroud)

说,它会一直使用最新的。

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

到目前为止的解决方案是:我们应该注册一个多租户 AAD …

node.js adal passport-azure-ad

3
推荐指数
1
解决办法
883
查看次数

将 state/customState 与 Passport-azure-ad 结合使用

我无法弄清楚它的目的customState以及是否/如何利用它来将数据传递到返回网址。具体来说,我希望在登录后将用户路由回其原始位置。我想我可以将原始 url 传递给参数customState,并在 return url 中将其返回给我POST,但它似乎已被编码或可能被替换为不同的值。

这是我想要实现的目标:

  1. 匿名用户访问/page/protected需要身份验证。
  2. 代码调用passport.authenticate进而重定向用户进行登录。
  3. 用户登录并返回到预先配置的返回 URL,例如:/auth/oidc/return
  4. 代码处理从表单发布数据中提取信息。
  5. 用户被引导回/page/protected

node.js adal openid-connect azure-ad-b2c passport-azure-ad

3
推荐指数
1
解决办法
1653
查看次数

带有 Passport.js 错误的 Azure Active Directory B2C“无法获取广告联合元数据”错误

我正在尝试使用 Passport.js 和 Azure Active Directory B2C 和 OpenID Connect 策略为我的 Node.js Web 应用程序实施面向客户的身份验证。

我已经按照官方 GitHub 页面的 README 说明研究了官方示例应用程序的源代码,但它们似乎不完整和/或已过时,正如在线各个线程所同意的那样。

在将网络上的各种提示拼凑起来后,我已经越过许多桥梁,但由于以下错误而陷入僵局:

cannot get AAD Federation metadata from endpoint you specified.

AAD 身份验证需要大量配置,因此我将注意一些重要值:

  • policyName:这是b2c_1_signin,就像我在 Azure 门户中配置的一样。
  • identityMetadata:我正在使用特定于租户的 v2.0 端点。我添加?p=b2c_1_signin了注入策略名称。
  • responseTypeid_token
  • redirectUrl:这是我在 Azure 中配置的本地主机和端口。allowHttpForRedirectUrl设置为true。(这适用于非生产环境。)
  • isB2Ctrue

node.js passport.js azure-ad-b2c azure-ad-msal passport-azure-ad

2
推荐指数
1
解决办法
1602
查看次数

将 Passport-azure-ad OIDCStrategy 与 Passportjs 一起使用时出现问题

我正在尝试使用 Passport-azure-ad 来验证用户身份。该应用程序显示常见的登录屏幕,但当我点击“登录”时,浏览器窗口变为空白并显示一个指示其工作的微调器。与此同时,我的服务器正在接收发送到我的回调端点的连续 POST 请求流。

在此期间,我的护照功能(验证、序列化用户和反序列化用户)都没有被调用。

这是我的策略定义:

    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);
})   
Run Code Online (Sandbox Code Playgroud)

这是我的路线定义:

app.get("/auth/azure", passport.authenticate('azure', {failureRedirect: '/'}))

app.post("/auth/azure/callback", …
Run Code Online (Sandbox Code Playgroud)

node.js adal passport.js passport-azure-ad

2
推荐指数
1
解决办法
2624
查看次数

如何使用 graphql 和护照设置身份验证,但仍使用 Playground

将身份验证添加到后端 Graphql 服务器后,“Schema”和“Docs”在 Graphql Playground 中不再可见。在 Playground 中向“HTTP HEADERS”添加令牌时执行查询在经过身份验证时可以正常工作,而在用户未经身份验证时则不能正常工作,所以没关系。

我们禁用了 Apollo 服务器的内置 Playground,并使用中间件graphql-playground-middleware-express来使用不同的 URL 并绕过身份验证。我们现在可以浏览到 Playground 并使用它,但我们无法读取那里的“架构”或“文档”。

尝试启用introspection并没有解决此问题。passport.authenticate()打电话过来会更好Contextapollo-server?还有一个名为Passport-graphql 的工具,但它适用于本地策略,可能无法解决问题。我还尝试在调用 Playground 路由之前在标头中设置令牌,但这不起作用。

我们对此有点迷失。感谢您为我们提供的任何见解。

在此输入图像描述

相关代码:

// index/ts
import passport from 'passport'
import expressPlayground from 'graphql-playground-middleware-express'

const app = express()
app.use(cors({ origin: true }))
app.get('/playground', expressPlayground({ endpoint: '/graphql' }))
app.use(passport.initialize())
passport.use(bearerStrategy)

app.use(
  passport.authenticate('oauth-bearer', { session: false }),
  (req, _res, next) => { next() }
)
;(async () => { …
Run Code Online (Sandbox Code Playgroud)

express passport.js graphql apollo-server passport-azure-ad

2
推荐指数
1
解决办法
4954
查看次数

如何在 Node.js 应用程序/API 中从 Azure AD 发出令牌?

我正在构建一个带有快速后端的节点应用程序。要求之一是使用 Azure AD 进行身份验证。我已经安装了passport-azure-ad模块并将其设置如下:

import * as passportAD from "passport-azure-ad";
// ... <snip> ....
const tenantName = "<MY_TENANT_NAME>"";
const clientID = "<MY_CLIENT_ID>";

app.use(passport.initialize());
app.use(passport.session());
const bearerStrategy = new passportAD.BearerStrategy(
  {
    identityMetadata: `https://login.microsoftonline.com/${tenantName}.onmicrosoft.com/.well-known/openid-configuration`,
    clientID
  },
  (token: any, done: any) => {
    console.log(token);
    return done(null, {}, token);
  }
);
passport.use(bearerStrategy);
Run Code Online (Sandbox Code Playgroud)

然后我为这样的路线添加了授权:

const myHandler = () => (req, res) => return res.json({});
app.get('/my/route',
        passport.authenticate("oauth-bearer", { session: false }),
        myHandler()
);
Run Code Online (Sandbox Code Playgroud)

这将按预期返回 401 状态,但是,我无法找到有关如何从 Azure AD 向客户端颁发令牌的文档。我想在正文中使用用户名和密码接受对登录端点的 POST 并返回 Azure AD 令牌。这可能吗?

node.js express azure-active-directory passport.js passport-azure-ad

0
推荐指数
1
解决办法
3065
查看次数

Nestjs - 实施 Azure-Ad 护照身份验证

如何实施 Azure-Ad Passport 身份验证?找不到任何相关文档,并在网上阅读发现存在问题。

authentication azure passport.js passport-azure-ad nestjs

0
推荐指数
1
解决办法
5815
查看次数