SAML Protocol server middleware

SAML Protocol middleware to create SAMLP identity providers for node.js.

npm install samlp

This middleware is meant to generate a valid SAML Protocol identity provider endpoint that speaks saml.

The idea is that you will use another mechanism to validate the user first.

The endpoint supports metadata as well in the url /FederationMetadata/2007-06/FederationMetadata.xml.


certpublic key used by this identity providerREQUIRED
keyprivate key used by this identity providerREQUIRED
getPostURLget the url to post the token f(audience, samlRequestDom, req, callback)REQUIRED
issuerthe name of the issuer of the tokenREQUIRED
audiencethe audience for the saml tokenreq.query.SAMLRequest.Issuer
getUserFromRequesthow to extract the user information from requestfunction(req) { return req.user; }
profileMappermapper to map users to claims (see PassportProfileMapper)PassportProfileMapper
signatureAlgorithmsignature algorithm, options: rsa-sha1, rsa-sha256'rsa-sha256'
digestAlgorithmdigest algorithm, options: sha1, sha256'sha256'
RelayStatestate of the auth process```req.query.RelayState
sessionIndexthe index of a particular session between the principal identified by the subject and the authenticating authoritySessionIndex is not included
responseHandlercustom response handler for SAML response f(SAMLResponse, req, res, next)HTML response that POSTS to postUrl

Add the middleware as follows:

app.get('/samlp', samlp.auth({
  issuer:     'the-issuer',
  cert:       fs.readFileSync(path.join(__dirname, 'some-cert.pem')),
  key:        fs.readFileSync(path.join(__dirname, 'some-cert.key')),
  getPostURLfunction (wtrealmwreplyreqcallback) { 
                return cb( null, '')

This module also support generating SAML Protocol metadata (IDPSsoDescriptor):

app.get('/samlp/FederationMetadata/2007-06/FederationMetadata.xml', samlp.metadata({
  issuer:   'the-issuer',
  cert:     fs.readFileSync(path.join(__dirname, 'some-cert.pem')),

It also accept two optionals parameters:

  • profileMapper: a class implementing the profile mapper. This is used to render the claims type information (using the metadata property). See PassportProfileMapper for more information.
  • endpointPath: this is the full path in your server to the auth route. By default the metadata handler uses the metadata request route without /FederationMetadata/2007..blabla.

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


This project is licensed under the MIT license. See the LICENSE file for more info.