7.1.1 • Published 5 months ago

samlp v7.1.1

Weekly downloads
7,856
License
mit
Repository
github
Last release
5 months ago

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

Build Status

Installation

npm install samlp

Supported Node Versions

node >= 12

Introduction

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.

Login (Authentication Flow)

Usage

Options

NameDescriptionDefault
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'
signResponsewhether to sign the SAML responsefalse
signAssertionwhether to sign the SAML assertiontrue
RelayStatestate of the auth processreq.query.RelayState || req.body.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, options, 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')),
  getPostURL: function (wtrealm, wreply, req, callback) {
                return callback( null, 'http://someurl.com')
              }
}));

SAML Protocol Metadata

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.

Note: If x-forwarded-host or x-forwarded-proto are received during the HTTP request to the metadata endpoint the urls contained in the metadata will use those them as host or protocol respectively instead of the original ones from request.headers.host and request.protocol.

Logout - SLO (Single Logout)

Starting on version v2.0 Single Logout is supported (SAML 2.0 Single Logout Profile). General support for SLO among Session Participants is varies a lot. This module supports the following flows:

  • IdP Initiated: a logout is initiated by invoking the GET logout endpoint specified in the IdP metadata. The IdP creates a signed SAML LogoutRequest and propagates it to the involved Session Participants.
  • SP Initiated: a Session Participant starts a SLO by sending a SAML LogoutRequest to the IdP. The IdP propagates it to the involved Session Participants.

Both flows need the IdP to accept SAML LogoutResponses from the Session Participants. This is also supported by this module.

Usage

Options

NameDescriptionDefault
certpublic key used by this identity providerREQUIRED
keyprivate key used by this identity providerREQUIRED
issuerthe name of the issuer of the tokenREQUIRED
protocolBindingthe binding to use'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
sessionParticipantsan object that handles Session Participants. Check this implementationAn empty object. It is REQUIRED if you want to use SLO
clearIdPSessiona function to be called when the logout process is finished so the IdP can clean its sessionfunction (cb){ return cb();
storean object that handles the HTTP Session. Check this implementationnew SessionStore(options) Uses req.session to store the current state

Notes

  • options.cert: This is the public certificate of the IdP
  • options.key: This is the private key of the IdP. The IdP will sign its SAML LogoutRequest and LogoutResponse with this key.
  • options.store: Since the logout flow will involve several requests/responses, we need to keep track of the transaction state. The default implementation uses req.session to store the transaction state via the 'flowstate' module
  • options.sessionParticipants: Will handle SessionParticipant objects. Each SessionParticipant object needs to have the following structure:
var sessionParticipant = {
  serviceProviderId : 'https://foobarsupport.zendesk.com', // The Issuer (Session Participant id)
  nameId: 'foo@example.com', // NameId Of the logged in user in the SP
  nameIdFormat: 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient', // Format of the NameId
  sessionIndex: '1', // The session index generated by the IdP
  serviceProviderLogoutURL: 'https://foobarsupport.zendesk.com/logout', // The logout URL of the Session Participant
  cert: sp1_credentials.cert, // The Session Participant public certificate, used to verify the signature of the SAML requests made by this SP
  binding: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST' // Optional, participant-specific binding to use during SLO, if not provided - will use "protocolBinding" from provided options
};

In some situations it is possible for session participants to have mixed bindings during one Single Log Out (SLO) transaction. By default the library will use the binding specified in options.protocolBinding, however if mixed bindings must be used - each participant must have the binding specified as an additional field. If the binding value is invalid - it will fall back to HTTP-POST.

Add the middleware as follows:

  app.get('/logout', samlp.logout({
      deflate:            true,
      issuer:             'the-issuer',
      protocolBinding:    'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
      cert:               fs.readFileSync(path.join(__dirname, 'some-cert.pem')),
      key:                fs.readFileSync(path.join(__dirname, 'some-cert.key'))
  }));

  app.post('/logout', samlp.logout({
      issuer:             'the-issuer',
      protocolBinding:    'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
      cert:               fs.readFileSync(path.join(__dirname, 'some-cert.pem')),
      key:                fs.readFileSync(path.join(__dirname, 'some-cert.key'))
  }));

Error handling

Errors are not sent back to the SP. To do so, you'll need to use the sendError middleware.

samlp.sendError({
    RelayState:         'relayState',
    issuer:             'the-issuer',
    signatureAlgorithm: 'rsa-sha1',
    digestAlgorithm:    'sha1',
    cert:               fs.readFileSync(path.join(__dirname, 'some-cert.pem')),
    key:                fs.readFileSync(path.join(__dirname, 'some-cert.key')),
    error: { description: err.message },
    getPostURL: function (req, callback) {
      callback(null, 'http://someurl.com');
    }
})(req, res, next);

Issue Reporting

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.

Author

Auth0

License

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

7.1.1

5 months ago

7.1.0

9 months ago

7.0.2

2 years ago

7.0.1

2 years ago

7.0.0

2 years ago

6.0.2

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.1

3 years ago

3.4.2

4 years ago

4.0.0

4 years ago

4.0.0-rc.0

4 years ago

3.5.0

4 years ago

3.4.4

4 years ago

3.4.3

4 years ago

3.4.1

5 years ago

3.4.0

6 years ago

3.3.4

6 years ago

3.3.3

6 years ago

3.3.2

7 years ago

3.3.1

7 years ago

3.3.0

7 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.15.2

8 years ago

0.15.1

8 years ago

0.15.0

8 years ago

0.14.0

8 years ago

0.13.2

8 years ago

0.13.1

8 years ago

0.13.0

9 years ago

0.12.3

9 years ago

0.12.2

9 years ago

0.12.1

9 years ago

0.12.0

9 years ago

0.11.0

9 years ago

0.10.2

9 years ago

0.10.1

9 years ago

0.10.0

9 years ago

0.9.0

9 years ago

0.8.4

10 years ago

0.8.3

10 years ago

0.8.2

10 years ago

0.8.1

10 years ago

0.8.0

10 years ago

0.7.0

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.8

10 years ago

0.4.7

10 years ago

0.4.6

11 years ago

0.4.5

11 years ago

0.4.4

11 years ago

0.4.3

11 years ago

0.4.2

11 years ago

0.4.1

11 years ago

0.4.0

11 years ago

0.3.4

11 years ago

0.3.3

11 years ago

0.3.2

11 years ago

0.3.1

11 years ago

0.3.0

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago