简体   繁体   English

使用 Azure AD 与第 3 方进行 SSO

[英]SSO with a 3rd party using Azure AD

I have an organization wanting to do SSO using SAML 2.0 against my node.js based web app.我有一个组织想要对我的基于 node.js 的 Web 应用程序使用 SAML 2.0 进行 SSO。 When clicking a link for x.myapp.com, I want to utilize their IdP (which uses Azure AD with SAML 2.0) and redirect to my app and provide a few attributes to me.单击 x.myapp.com 的链接时,我想利用他们的 IdP(使用带有 SAML 2.0 的 Azure AD)并重定向到我的应用程序并向我提供一些属性。

I found passport-azure-ad and saml2-js npm packages but I don't see any examples that cover this scenario.我找到了passport-azure-ad 和saml2-js npm 包,但我没有看到任何涵盖这种情况的示例。 Has anyone done this seemingly simple use case and provide any links or examples?有没有人做过这个看似简单的用例并提供任何链接或示例? I only found iOS or Android examples thus far but not web-based node.js apps.到目前为止,我只找到了 iOS 或 Android 示例,但没有找到基于 Web 的 node.js 应用程序。

Thank you.谢谢你。

Per my understanding , you are looking for a Azure AD SAML login nodejs demo.根据我的理解,您正在寻找 Azure AD SAML 登录 nodejs 演示。 This demo will be helpful for you and it works for me. 这个演示对你有帮助,对我有用。

If you want to use Azure AD as your idp, you should do some modify as below :如果你想使用 Azure AD 作为你的 idp,你应该做一些如下修改:

1.Create a folder named "cert" . 1.创建一个名为“cert”的文件夹。 Run this command to create key.pem and cert.pem under cert folder:运行此命令在 cert 文件夹下创建 key.pem 和 cert.pem:

openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out cert.pem
  1. Go to Azure AD ,download idp cert here ,rename it as "cert_idp.pem" directly and place it under cert folder too :转到 Azure AD,在此处下载 idp 证书,直接将其重命名为“cert_idp.pem”并将其也放在 cert 文件夹下: 在此处输入图片说明 在此处输入图片说明 3.Creatring a file named ".env" with content below : 3.创建一个名为“.env”的文件,内容如下:

 CALLBACK_URL=https://<your host>/login/callback ENTRY_POINT=<find the value in the capture below> ISSUER=<your Azure AD APP ID> SESSION_SECRET=secret

在此处输入图片说明

With the steps done , you can run this demo .完成这些步骤后,您就可以运行这个演示了。 in my case, I expose 4006 port to public network using ngrok , once you access the app , you will be redirected to Azure AD SAML login page to login:就我而言,我使用 ngrok 将 4006 端口暴露给公共网络,一旦您访问该应用程序,您将被重定向到 Azure AD SAML 登录页面进行登录: 在此处输入图片说明

Modify the get method under "/" as below to get MSAL token info after you logged in successfully:修改“/”下的get方法如下,登录成功后获取MSAL令牌信息:

app.get('/',
  ensureAuthenticated, 
  function(req, res) {
    res.send('Authenticated, SAML token info :'  + JSON.stringify(req.session.passport.user));
  }
);

If there is anything unclear , pls feel free to let me know : )如果有任何不清楚的地方,请随时告诉我 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM