使用 OneLogin 实现 Node.js SAML

标签 node.js saml onelogin passport-saml

我希望在 OneLogin 的应用程序目录中设置我们的应用程序,因此据我了解,我需要创建 SAML 集成。我确实看到他们有可用的工具包,但我正在 Node.js 中工作,并且没有适合该环境的工具包。

我一直在阅读他们的文档以及其他帖子,并认为该过程如下所示: 1) 向 OneLogin 发出创建应用程序并将其添加到其目录中的请求。 2) 我的应用程序需要有一个路由点,我将向 OneLogin 提供该路由点,当有人单击我们应用程序的图标时,该路由点将用作重定向。 3) 用户单击目录中我的应用程序的图标将对用户进行标记,并将其发送到我定义的路由点,并将信息作为 SAML 请求/XML 传递。 4) 我的路由点需要使用 SAML 请求/XML,然后执行我的内部登录过程。 OneLogin 传递到我的路由点的信息将包括我的网站的必要信息,例如名字、姓氏和电子邮件地址。然后,我将使用该信息执行我的内部应用程序,如果它对现有用户进行验证,我会将其视为成功登录,然后让他们继续。如果他们不是现有用户,我将通过用户创建类型表单向他们发送,但可以使用来自 OneLogin 的 SAML 请求/XML 的默认信息,或者可以自动创建用户。

这看起来我对这个过程有很高的了解吗?

有人有 Node.js 的例子吗?

我打算使用 Passport-SAML 包。

最佳答案

是的,您走在正确的道路上。

Passport-SAML 非常适合 Express 应用 https://github.com/bergie/passport-saml

您的 Passport SAML 策略配置应如下所示。

passport.use(new SamlStrategy(
  {
    path: '/login/callback',
    entryPoint: 'https://{SUBDOMAIN}.onelogin.com/trust/saml2/http-redirect/sso/{APP_ID}',
    issuer: 'passport-saml'
  },
  function(profile, done) {
    console.log(profile);
    return done(null, profile);
  })
);

passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(obj, done) {
  done(null, obj);
});

请务必使用通过 OneLogin 门户配置应用程序时提供的 SLO 端点。

然后设置您的路线以使用 Passport

// Initiates an authentication request with OneLogin
// The user will be redirect to OneLogin and once authenticated
// they will be returned to the callback handler below
app.get('/login', passport.authenticate('saml', {
  successReturnToOrRedirect: "/"
}));

// Callback handler that OneLogin will redirect back to
// after successfully authenticating the user
app.post('/login/callback', passport.authenticate('saml', {
  callback: true,
  successReturnToOrRedirect: '/users',
  failureRedirect: '/'
}))

您还需要确保已将 ACS(消费者)URL 设置为您的应用回调 URL,并且您正在测试的用户有权访问该应用。

关于使用 OneLogin 实现 Node.js SAML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46167341/

相关文章:

javascript - XMLHttpRequest 已被 CORS 策略阻止 - https ://openid-connect-eu. onelogin.com/oidc/token

javascript - 如何使用 NodeJS 和 Express 获取数据以显示行数?

node.js - mongodb查询获取两个日期范围内的文档

apache - 没有可用的MetadataProvider-shibsp::ConfigurationException

file - OneLogin one.saml.properties 文件

SAML2元数据-多个签名证书

android - 用于 native 移动应用程序(Android 和 IOS)的 SAML

java - Java 版 OneLogin : configure certificate and PK

node.js - Angular 2 服务中的 Node-Forge 导入

javascript - 在服务器上渲染或更新 react 元素