saml2-js is a Node.js module that simplifies the implementation of the SAML 2.0 protocol, specifically for acting as a Service Provider (SP). It abstracts away complexities, allowing applications to integrate with Identity Providers (IdPs) for authentication and authorization. The library currently does not support acting as an Identity Provider. As of version 4.0.4, the project is in maintenance mode, focusing primarily on addressing bug reports and security issues rather than feature development. There is no stated regular release cadence, with updates being driven by critical fixes. Key differentiators include its focus solely on SP functionality and a clear set of configuration options for managing SAML requests and responses. It offers constructors for `ServiceProvider` and `IdentityProvider` objects, with options for managing entity IDs, cryptographic keys, assertion endpoints, and various SAML-specific behaviors like `force_authn` and `nameid_format`.
npm install saml2-jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure a Service Provider and Identity Provider, generate a SAML login request URL for SP-initiated SSO, and generate SP metadata for IdP configuration.
Developers requiring new SAML features or extensive support should consider alternative, actively developed SAML libraries for Node.js.
Ensure `allow_unencrypted_assertion` is `false` in production environments unless explicitly required and protected by robust transport-level security. Always use HTTPS for SAML communication.
Tune `notbefore_skew` carefully. Start with a small positive integer (e.g., 60 seconds) and monitor logs. Avoid setting it to a very large number, which could compromise security. Synchronize server clocks (NTP) for both IdP and SP.
Verify that the `audience` specified in the `ServiceProvider` configuration (or defaulted to `entity_id`) exactly matches one of the `<Audience>` values present in the IdP's SAML responses.
Load keys and certificates from secure environment variables, a secret management service, or encrypted files. Ensure private keys have restricted file system permissions. Implement key rotation policies.
If Identity Provider functionality is required, select a different SAML library specifically designed for IdP implementations.
Use `const saml2 = require('saml2-js');` and then `new saml2.ServiceProvider(...)`.Provide a unique identifier string for `entity_id` in the `ServiceProvider` options object.
Update the `audience` option in `ServiceProvider` to precisely match one of the valid audience values provided by the Identity Provider.
Synchronize the server clocks using NTP. Consider increasing the `notbefore_skew` option in `ServiceProvider` slightly (e.g., to 60 seconds) to tolerate minor clock differences.
Verify that the `private_key` configured for the `ServiceProvider` is the correct private key corresponding to the certificate used by the IdP for encryption. Ensure the PEM format is correct and there are no extra characters.
No dependency data recorded yet.