gpt4 book ai didi

node.js - 有人成功使用 Azure AD 对 Node.js Web 应用程序的用户进行身份验证吗?

转载 作者:IT老高 更新时间:2023-10-28 23:25:27 29 4
gpt4 key购买 nike

我正在尝试使用 Azure Active Directory 对我的 node.js Web 应用程序的用户进行身份验证,但到目前为止还没有成功。

我想知道是否有人真正实现了它,因为文档非常糟糕。通常有示例代码,但实际上没有任何指示所需参数是什么以及它们应该是什么。

我尝试过passport-azure-ad(我认为来自Microsoft)和passport.azure-ad-oauth2(来自Auth0(?))。对于 Passport-azure-ad,我尝试了 BearerStrategy 和 OIDCStrategy,但没有成功。

对于 BearerStrategy,我收到一些关于我的客户端和识别同一应用程序的资源的神秘消息,但由于没有文档告诉我这些应该是什么,所以我不知所措。

对于 OIDCStrategy,我更接近一点,因为我被重定向到 Microsoft 进行身份验证,但返回时我收到错误“错误:响应中不存在 ID token ”。我猜测我的请求不够正确,无论出于何种原因都无法给我返回 token ,但由于没有文档......(你明白了)。

无论如何,如果有人真正成功地实现了它,并且能够分享一些关于如何实现它的指导,那就太好了。

非常感谢。

最佳答案

下面是一个代码示例,用于将 Azure AD 集成到 Microsoft 在 GitHub 上提供的 NodeJS Web 应用程序中,地址为 https://github.com/Azure-Samples/active-directory-node-webapp-openidconnect .

为了使示例运行,您需要在示例代码中配置一些有关 Azure AD 的设置。

我们可以在应用根目录下的config.js文件中找到如下内容:

exports.creds = {
returnURL: 'http://localhost:3000/auth/openid/return',
identityMetadata: 'https://login.microsoftonline.com/common/.well-known/openid-configuration', // For using Microsoft you should never need to change this.
clientID: '<your app id>',
clientSecret: '<your secret>', // if you are doing code or id_token code
skipUserProfile: true, // for AzureAD should be set to true.
responseType: 'id_token code', // for login only flows use id_token. For accessing resources use `id_token code`
responseMode: 'query', // For login only flows we should have token passed back to us in a POST
//scope: ['email', 'profile'] // additional scopes you may wish to pass
};

现在您需要登录 Azure 管理门户,标题为您的 Azure AD 应用程序页面。单击配置选项卡来配置您的 AD。

  • config.js 中的 returnURL 输入到单点登录部分下的 REPLY URL 表单中: enter image description here

  • 将 AD 应用程序的 Azure AD 端点填充到 config.js 中的 identityMetadata 属性中。正如代码中的注释所示,如果您的 Azure AD 位于 Microsoft 域中,例如:enter image description here那么您就不必更改设置。否则,您需要将config.js中端点中的common替换为您的AD ID,您可以点击底部的VIEW ENDPOINT nav 查找 ID:enter image description here

  • config.js中配置clientIDclientSecret。您都可以在 AD 应用程序的 CONFIGRE 页面中找到它们: enter image description here关于 key ,您可以选择下拉菜单选择 key 的持续时间来创建新的 key ,单击底部导航栏的保存按钮,您可以在第一次创建 key 时看到 key 数据。

    <

完成这些步骤后,您可以尝试示例项目。

关于node.js - 有人成功使用 Azure AD 对 Node.js Web 应用程序的用户进行身份验证吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34996807/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com