|
1 | 1 | var util = require('util');
|
2 | 2 | var saml = require('./lib/passport-saml/saml');
|
| 3 | +var InMemoryCacheProvider = require('./lib/passport-saml/inmemory-cache-provider').CacheProvider; |
3 | 4 | var SamlStrategy = require('./lib/passport-saml/strategy');
|
4 | 5 |
|
5 | 6 | function MultiSamlStrategy (options, verify) {
|
6 | 7 | if (!options || typeof options.getSamlOptions != 'function') {
|
7 | 8 | throw new Error('Please provide a getSamlOptions function');
|
8 | 9 | }
|
9 | 10 |
|
| 11 | + if(!options.requestIdExpirationPeriodMs){ |
| 12 | + options.requestIdExpirationPeriodMs = 28800000; // 8 hours |
| 13 | + } |
| 14 | + |
| 15 | + if(!options.cacheProvider){ |
| 16 | + options.cacheProvider = new InMemoryCacheProvider( |
| 17 | + {keyExpirationPeriodMs: options.requestIdExpirationPeriodMs }); |
| 18 | + } |
| 19 | + |
10 | 20 | SamlStrategy.call(this, options, verify);
|
11 |
| - this._getSamlOptions = options.getSamlOptions; |
| 21 | + this._options = options; |
12 | 22 | }
|
13 | 23 |
|
14 | 24 | util.inherits(MultiSamlStrategy, SamlStrategy);
|
15 | 25 |
|
16 | 26 | MultiSamlStrategy.prototype.authenticate = function (req, options) {
|
17 | 27 | var self = this;
|
18 | 28 |
|
19 |
| - this._getSamlOptions(req, function (err, samlOptions) { |
| 29 | + this._options.getSamlOptions(req, function (err, samlOptions) { |
20 | 30 | if (err) {
|
21 | 31 | return self.error(err);
|
22 | 32 | }
|
23 | 33 |
|
24 |
| - self._saml = new saml.SAML(samlOptions); |
| 34 | + self._saml = new saml.SAML(Object.assign({}, self._options, samlOptions); |
25 | 35 | self.constructor.super_.prototype.authenticate.call(self, req, options);
|
26 | 36 | });
|
27 | 37 | };
|
28 | 38 |
|
29 | 39 | MultiSamlStrategy.prototype.logout = function (req, options) {
|
30 | 40 | var self = this;
|
31 | 41 |
|
32 |
| - this._getSamlOptions(req, function (err, samlOptions) { |
| 42 | + this._options.getSamlOptions(req, function (err, samlOptions) { |
33 | 43 | if (err) {
|
34 | 44 | return self.error(err);
|
35 | 45 | }
|
36 | 46 |
|
37 |
| - self._saml = new saml.SAML(samlOptions); |
| 47 | + self._saml = new saml.SAML(Object.assign({}, self._options, samlOptions); |
38 | 48 | self.constructor.super_.prototype.logout.call(self, req, options);
|
39 | 49 | });
|
40 | 50 | };
|
|
0 commit comments