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

Create a way to get provider metadata when using the MultiSamlStrategy #323

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ The `decryptionCert` argument should be a public certificate matching the `decry

The `signingCert` argument should be a public certificate matching the `privateCert` and is required if the strategy is configured with a `privateCert`.

The `generateServiceProviderMetadata` method is also available on the `MultiSamlStrategy`, but needs an extra request and a callback argument (`generateServiceProviderMetadata( req, decryptionCert, signingCert, next )`), which are passed to the `getSamlOptions` to retrieve the correct configuration.


## Security and signatures

Expand Down
13 changes: 13 additions & 0 deletions multiSamlStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@ MultiSamlStrategy.prototype.logout = function (req, options) {
});
};

MultiSamlStrategy.prototype.generateServiceProviderMetadata = function( req, decryptionCert, signingCert, next ) {
var self = this;

return this._getSamlOptions(req, function (err, samlOptions) {
if (err) {
return next(err);
}

self._saml = new saml.SAML(samlOptions);
return next(null, self.constructor.super_.prototype.generateServiceProviderMetadata.call(self, decryptionCert, signingCert ));
});
};

module.exports = MultiSamlStrategy;
69 changes: 69 additions & 0 deletions test/multiSamlStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,72 @@ describe('strategy#logout', function() {
strategy.logout();
});
});

describe('strategy#generateServiceProviderMetadata', function() {
beforeEach(function() {
this.superGenerateServiceProviderMetadata = sinon.stub(SamlStrategy.prototype, 'generateServiceProviderMetadata').returns('My Metadata Result');
});

afterEach(function() {
this.superGenerateServiceProviderMetadata.restore();
});

it('calls super with request and generateServiceProviderMetadata options', function(done) {
var superGenerateServiceProviderMetadata = this.superGenerateServiceProviderMetadata;
function getSamlOptions (req, fn) {
fn();
sinon.assert.calledOnce(superGenerateServiceProviderMetadata);
superGenerateServiceProviderMetadata.calledWith('bar', 'baz');
req.should.eql('foo');
done();
};


var strategy = new MultiSamlStrategy({ getSamlOptions: getSamlOptions }, verify);
strategy.generateServiceProviderMetadata('foo', 'bar', 'baz', function () {});
});

it('passes options on to saml strategy', function(done) {
var passportOptions = {
passReqToCallback: true,
authnRequestBinding: 'HTTP-POST',
getSamlOptions: function (req, fn) {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
}
};

var strategy = new MultiSamlStrategy(passportOptions, verify);
strategy.generateServiceProviderMetadata('foo', 'bar', 'baz', function () {});
});

it('should pass error to callback function', function(done) {
var passportOptions = {
getSamlOptions: function (req, fn) {
fn('My error');
}
};

var strategy = new MultiSamlStrategy(passportOptions, verify);
strategy.generateServiceProviderMetadata('foo', 'bar', 'baz', function (error, result) {
should(error).equal('My error');
done();
});
});

it('should pass result to callback function', function(done) {
var passportOptions = {
getSamlOptions: function (req, fn) {
fn();
}
};

var strategy = new MultiSamlStrategy(passportOptions, verify);
strategy.generateServiceProviderMetadata('foo', 'bar', 'baz', function (error, result) {
should(result).equal('My Metadata Result');
done();
});
});
});