Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strategy options based on req #131

Open
neemah opened this issue Jun 18, 2019 · 1 comment
Open

Strategy options based on req #131

neemah opened this issue Jun 18, 2019 · 1 comment

Comments

@neemah
Copy link

neemah commented Jun 18, 2019

Hello, thanks for library, it works like a charm.

But there is one problem we are currently facing – we need to configurate strategy based on req data.

Currently:

new wsfedsaml2({
	// ADFS RP identifier
	realm: 'urn:node:wsfedapp',
	identityProviderUrl: 'https://my-adfs/adfs/ls',
	// ADFS token signing certificate
	thumbprint: '5D27....D27E'
	// or cert: fs.readFileSync("adfs_signing_key.cer")
}, function (profile, done) {
 // ...
}))

And we need:

const getParams = req => {
   return {
     .... req based params
   }
}

new wsfedsaml2(getParams, function (profile, done) {
 // ...
}))

How do we achieve that?

@neemah
Copy link
Author

neemah commented Jun 21, 2019

This is how we "patched" strategy to use it in multihost environment (SaaS like ours):

const _ = require('lodash');
const url = require('url');
const { Strategy: Wsfedsaml2 } = require('passport-wsfed-saml2');

class WsfedSaml2Strategy extends Wsfedsaml2 {
  constructor (getConfiguration, verify) {
    if (!_.isFunction(getConfiguration)) {
      throw new Error('Please provide a finder method');
    }
    super({
      cert: '=' // for saml base64 checking in constructor
    }, verify);
    this._getConfiguration = getConfiguration;
  }

  authenticate (req, options = {}) {
    this._getConfiguration(req, (err, configuration) => {
      if (err) {
        return this.fail(err);
      }
      this.options = configuration;
      this.options.protocol = this.options.protocol || 'wsfed';
      this._passReqToCallback = !!configuration.passReqToCallback;
      this._saml = new this._saml.constructor(this.options);
      this._samlp = new this._samlp.constructor(this.options, this._saml);
      this._wsfed.realm = configuration.realm;
      this._wsfed.homerealm = configuration.homerealm;
      this._wsfed.identityProviderUrl = configuration.identityProviderUrl;
      this._wsfed.wreply = configuration.wreply;

      this._key = configuration.sessionKey || `${this.options.protocol}:${url.parse(configuration.identityProviderUrl || '').hostname}`;
      // this is not fully wrap original configuration
      // store, state and eventEmitter are not overrided - see this https://github.com/auth0/passport-wsfed-saml2/blob/master/lib/passport-wsfed-saml2/strategy.js#L48
      return super.authenticate(req, options);
    });
  }
}

module.exports = { Strategy: WsfedSaml2Strategy };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant