forked from node-saml/passport-saml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiSamlStrategy.js
69 lines (53 loc) · 2.16 KB
/
multiSamlStrategy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var util = require('util');
var saml = require('./lib/passport-saml/saml');
var InMemoryCacheProvider = require('./lib/passport-saml/inmemory-cache-provider').CacheProvider;
var SamlStrategy = require('./lib/passport-saml/strategy');
function MultiSamlStrategy (options, verify) {
if (!options || typeof options.getSamlOptions != 'function') {
throw new Error('Please provide a getSamlOptions function');
}
if(!options.requestIdExpirationPeriodMs){
options.requestIdExpirationPeriodMs = 28800000; // 8 hours
}
if(!options.cacheProvider){
options.cacheProvider = new InMemoryCacheProvider(
{keyExpirationPeriodMs: options.requestIdExpirationPeriodMs });
}
SamlStrategy.call(this, options, verify);
this._options = options;
}
util.inherits(MultiSamlStrategy, SamlStrategy);
MultiSamlStrategy.prototype.authenticate = function (req, options) {
var self = this;
this._options.getSamlOptions(req, function (err, samlOptions) {
if (err) {
return self.error(err);
}
self._saml = new saml.SAML(Object.assign({}, self._options, samlOptions));
self.constructor.super_.prototype.authenticate.call(self, req, options);
});
};
MultiSamlStrategy.prototype.logout = function (req, callback) {
var self = this;
this._options.getSamlOptions(req, function (err, samlOptions) {
if (err) {
return callback(err);
}
self._saml = new saml.SAML(Object.assign({}, self._options, samlOptions));
self.constructor.super_.prototype.logout.call(self, req, callback);
});
};
MultiSamlStrategy.prototype.generateServiceProviderMetadata = function( req, decryptionCert, signingCert, callback ) {
if (typeof callback !== 'function') {
throw new Error("Metadata can't be provided synchronously for MultiSamlStrategy.");
}
var self = this;
return this._options.getSamlOptions(req, function (err, samlOptions) {
if (err) {
return callback(err);
}
self._saml = new saml.SAML(Object.assign({}, self._options, samlOptions));
return callback(null, self.constructor.super_.prototype.generateServiceProviderMetadata.call(self, decryptionCert, signingCert ));
});
};
module.exports = MultiSamlStrategy;