1 | const SamlStrategy = require( 'passport-saml' ).Strategy;
|
2 |
|
3 | const createConfig = ( config ) => {
|
4 |
|
5 | const { passport } = config;
|
6 | if ( !passport ) return {};
|
7 |
|
8 | const { saml } = passport;
|
9 |
|
10 | if ( typeof saml !== 'object' || config === null || saml === undefined ) {
|
11 | return {};
|
12 | }
|
13 |
|
14 |
|
15 | const cKeys = Object.keys( saml );
|
16 |
|
17 | return cKeys.reduce( ( obj, key ) => {
|
18 |
|
19 | const o = obj;
|
20 |
|
21 | o[key] = saml[key];
|
22 | return o;
|
23 |
|
24 | }, {} );
|
25 |
|
26 | };
|
27 |
|
28 | const defaultModel = ( profile, done ) => done( null, profile );
|
29 |
|
30 | module.exports = ( passport, config, modelFunction ) => {
|
31 |
|
32 | passport.serializeUser( ( user, done ) => {
|
33 | done( null, user );
|
34 | } );
|
35 |
|
36 | passport.deserializeUser( ( user, done ) => {
|
37 | done( null, user );
|
38 | } );
|
39 |
|
40 | passport.use(
|
41 | new SamlStrategy(
|
42 | createConfig( config ),
|
43 | modelFunction || config.passport.callbackModel || defaultModel
|
44 | )
|
45 | );
|
46 |
|
47 | };
|