From 594eed35cc0765172d17487b3611eddffaadd2ea Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Wed, 14 Feb 2018 13:15:45 -0500 Subject: [PATCH] New Feature: allow customizing the name of the strategy. Using this option, you instantiate the strategy multiple times with different configurations. --- README.md | 3 +++ lib/passport-saml/strategy.js | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3132c380..b6a1d55c 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,9 @@ passport.use(new SamlStrategy( * `cacheProvider`: Defines the implementation for a cache provider used to store request Ids generated in SAML requests as part of `InResponseTo` validation. Default is a built-in in-memory cache provider. For details see the 'Cache Provider' section. * **Passport** * `passReqToCallback`: if truthy, `req` will be passed as the first argument to the verify callback (default: `false`) + * `name`: Optionally, provide a custom name. (default: `saml`). Useful If you want to instantiate the strategy multiple times with different configurations, + allowing users to authenticate against multiple different SAML targets from the same site. You'll need to use a unique set of URLs + for each target, and use this custom name when calling `passport.authenticate()` as well. * **Logout** * `logoutUrl`: base address to call with logout requests (default: `entryPoint`) * `additionalLogoutParams`: dictionary of additional query params to add to 'logout' requests diff --git a/lib/passport-saml/strategy.js b/lib/passport-saml/strategy.js index 869ebf6e..82cd0a09 100644 --- a/lib/passport-saml/strategy.js +++ b/lib/passport-saml/strategy.js @@ -12,7 +12,15 @@ function Strategy (options, verify) { throw new Error('SAML authentication strategy requires a verify function'); } - this.name = 'saml'; + // Customizing the name can be useful to support multiple SAML configurations at the same time. + // Unlike other options, this one gets deleted instead of passed along. + if (options.name) { + this.name = options.name; + delete options.name; + } + else { + this.name = 'saml'; + } passport.Strategy.call(this);