Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

passport-saml-metadata

compwright63.6kMIT5.0.0TypeScript support: included

SAML2 metadata loader

node, passport, SAML, SAML2, passport-saml, passport-wsfed-saml2, metadata

readme

passport-saml-metadata

Build Status Download Status

Utilities for reading configuration from SAML 2.0 Metadata XML files, such as those generated by Active Directory Federation Services (ADFS).

Installation

npm install passport-saml-metadata

Usage Example

const os = require('os');
const fileCache = require('file-system-cache').default;
const { fetch, toPassportConfig, claimsToCamelCase } = require('passport-saml-metadata');
const SamlStrategy = require('passport-wsfed-saml2').Strategy;

const backupStore = fileCache({ basePath: os.tmpdir() });
const url = 'https://adfs.company.com/federationMetadata/2007-06/FederationMetadata.xml';

fetch({ url, backupStore })
  .then((reader) => {
    const config = toPassportConfig(reader);
    config.realm = 'urn:nodejs:passport-saml-metadata-example-app';
    config.protocol = 'saml2';

    passport.use('saml', new SamlStrategy(config, function(profile, done) {
      profile = claimsToCamelCase(profile, reader.claimSchema);
      done(null, profile);
    }));

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

    passport.deserializeUser((user, done) => {
      done(null, user);
    });
  });

See compwright/passport-saml-example for a complete reference implementation.

API

fetch(config = {})

When called, it will attempt to load the metadata XML from the supplied URL. If it fails due to a request timeout or other error, it will attempt to load from the backupStore cache.

Config:

  • client Axios instance
  • url (required) Metadata XML file URL
  • timeout Time to wait before falling back to the backupStore, in ms (default = 2000)
  • backupStore Any persistent cache adapter object with get(key) and set(key, value) methods (default = new Map())

Additional configuration options supported: https://github.com/axios/axios#request-config

Returns a promise which resolves, if successful, to an instance of MetadataReader.

toPassportConfig(reader, options = { multipleCerts: false })

Transforms metadata extracts for use in Passport strategy configuration. The following strategies are currently supported:

Config:

  • multipleCerts (boolean): causes the full array of signing certificates to be passed to the passport config instead of assuming the last certificate is the most recent one. Note: this option is not compatible with passport-wsfed-saml2.

claimsToCamelCase(claims, claimSchema)

Translates the claim identifier URLs to human-friendly camelCase versions. Useful in Passport verifier functions.

claimSchema should be an object of the following format, such as from MetadataReader.claimSchema():

{
  [claimURL]: {
    name: claimUrl,
    camelCase: 'claimIdentifierInCamelCase',
    description: 'Some description'
  },
  ...
}

Example:

function verifier(profile, done) {
  profile = passportSamlMetadata.claimsToCamelCase(profile, reader.claimSchema);
  done(null, profile);
}

new MetadataReader(metadataXml, options)

Options parameter details:

  • authnRequestBinding: if set to HTTP-POST, will attempt to load identityProviderUrl/logoutUrl via HTTP-POST binding in metadata, otherwise defaults to HTTP-Redirect
  • throwExceptions: if set to true, will throw upon exception

Parses metadata XML and extracts the following properties:

Methods:

  • query(query) - queries the metadataXml using XPath.

metadata(app)(config = {})

Returns a function which sets up an Express application route to generate the metadata XML file for your application at /FederationMetadata/2007-06/FederationMetadata.xml. ADFS servers may import the resulting file to set up the relying party trust.

Config:

  • issuer (required) The unique application identifier, used to name the relying party trust; may be a URN or URL
  • callbackUrl (required) The absolute URL to redirect back to with the SAML assertion after logging in, usually https://hostname[:port]/login/callback
  • logoutCallbackUrl The absolute URL to redirect back to with the SAML assertion after logging out, usually https://hostname[:port]/logout

See compwright/passport-saml-example for a usage example.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

5.0.0 (2025-03-18)

⚠ BREAKING CHANGES

  • drop support for node < 18

Features

  • drop support for node < 18 (b83e827)
  • upgrade to @xmldom/xmldom v0.9.8 and @node-saml/node-saml v5.0.1 (2a4b35f)

4.0.0 (2024-04-03)

⚠ BREAKING CHANGES

  • upgrade @node-saml/node-saml to v5 (#47)

  • upgrade @node-saml/node-saml to v5 (#47) (e185a0e)

3.2.0 (2023-10-13)

Features

  • make MetadataReader.query() public (#45) (3996537)

3.1.2 (2023-03-02)

Bug Fixes

  • add missing file extensions to lodash imports (#43) (cfce891), closes #42
  • test: fix test failure (1f3c001)

3.1.1 (2022-12-29)

Bug Fixes

  • add check for undefined cert (#38) (2903836)
  • update insecure dependencies (7876852)

3.1.0 (2022-12-22)

Features

  • add new entityId() method to MetadataReader (#41) (707f5e4), closes #40

Bug Fixes

3.0.0 (2022-12-14)

⚠ BREAKING CHANGES

  • Convert to es6 module
  • Drop support for Node.js v14

Features

  • add typescript type definitions (2233a92)
  • Convert to es6 module (fccec16)
  • Drop support for Node.js v14 (7a3e142)

Bug Fixes

  • replace deprecated passport-saml with @node-saml/node-saml (4298588), closes #39

2.6.2 (2022-10-17)

2.6.1 (2022-10-17)

2.6.0 (2022-05-24)

Merged pull requests:

2.5.0 (2021-09-13)

Full Changelog

Closed issues:

  • Update passport-saml to v3.1.0 fixes CVE-2021-39171 #33
  • Dependency to xmldom lib version which has security issues #32

2.4.1 (2021-03-10)

Full Changelog

2.4.0 (2020-12-16)

Full Changelog

Closed issues:

  • security alert for xml-crypto which has been updated in passport-saml 1.5.0 #31

2.3.0 (2020-06-01)

Full Changelog

Merged pull requests:

2.2.0 (2019-12-23)

Full Changelog

Closed issues:

  • pem_read_bio_pubkey failed, started sometime after 1.4 series #18

Merged pull requests:

2.1.0 (2019-08-17)

Full Changelog

Closed issues:

  • Adding option for adding a CA #17
  • fetch dosn't support self signed certificate #16
  • reader.claimSchema dosn't find any claims in my metadata.xml #15

2.0.1 (2019-08-17)

Full Changelog

2.0.0 (2019-08-17)

Full Changelog

Closed issues:

  • An in-range update of core-js is breaking the build 🚨 #14

Merged pull requests:

1.6.0 (2019-01-20)

Full Changelog

Merged pull requests:

1.5.2 (2018-09-11)

Full Changelog

Closed issues:

  • Action required: Greenkeeper could not be activated 🚨 #7
  • Action required: Greenkeeper could not be activated 🚨 #6

Merged pull requests:

1.5.1 (2018-08-29)

Full Changelog

Merged pull requests:

1.5.0 (2018-08-29)

Full Changelog

Closed issues:

  • MetadataReader - Add Support For HTTP-POST/HTTP-Artifact Authorization Bindings #4

Merged pull requests:

  • Adding support for alternate authorization bindings (#4) #5 (TigerC10)

1.4.0 (2018-04-26)

Full Changelog

Closed issues:

  • Update Dependencies #2

Merged pull requests:

  • Updating Dependencies (#2) #3 (TigerC10)
  • toPassportConfig: use entryPoint for passport-saml #1 (leachiM2k)

1.3.0 (2018-02-05)

Full Changelog

1.2.1 (2017-08-07)

Full Changelog

1.2.0 (2017-08-04)

Full Changelog

1.1.0 (2017-08-04)

Full Changelog

1.0.1 (2017-08-02)

Full Changelog

1.0.0 (2017-08-01)

Full Changelog

* This Changelog was automatically generated by github_changelog_generator