Skip to content

samlifyNode.js SAML 2.0 API

Node.js library for Single Sign-On with SAML 2.0

samlify

Installation

Install the stable release via npm:

bash
npm install samlify

Or via yarn:

bash
yarn add samlify

Supported use cases

  • IdP-initiated Single Sign-On
  • IdP-initiated Single Logout
  • SP-initiated Single Sign-On
  • SP-initiated Single Logout (in development)

A minimal identity provider implementation is included for testing and educational purposes. Integration with third-party identity providers is also supported.

Quick start

Breaking changes since v2

File attributes such as metadata and keyFile must now be passed as strings (or buffers). This enables integration with database storage, in-memory sources, and the local filesystem through a single interface.

The entity constructor now accepts a single configuration object rather than separate metadata and configuration arguments.

javascript
const saml = require('samlify');

// Configure a service provider.
const sp = saml.ServiceProvider({
  metadata: fs.readFileSync('./metadata_sp.xml')
});

// Configure the corresponding identity provider.
const idp = saml.IdentityProvider({
  metadata: fs.readFileSync('./metadata_idp.xml')
});

// Parse an inbound SAML Response sent by the IdP.
router.post('/acs', (req, res) => {
  sp.parseLoginResponse(idp, 'post', req)
    .then(parseResult => {
      // Apply your own validation and rendering logic here.
    })
    .catch(console.error);
});

By default, the library verifies the XML signature and the issuer name of the identity provider. The code base is self-documenting; additional use cases are covered throughout this documentation.

License

MIT