@@ -3,49 +3,42 @@ import passport from 'passport';
33import { signUpSaml } from '../services/admin.js' ;
44import Logger from '../helpers/logger.js' ;
55
6- function isSamlAvailable ( ) {
7- return process . env . SAML_ENTRY_POINT && process . env . SAML_CALLBACK_ENDPOINT_URL && process . env . SAML_CERT ;
8- }
6+ const samlOptions = {
7+ entryPoint : process . env . SAML_ENTRY_POINT ,
8+ issuer : process . env . SAML_ISSUER || 'switcher-api' ,
9+ callbackUrl : `${ process . env . SAML_CALLBACK_ENDPOINT_URL } /admin/saml/callback` ,
10+ idpCert : Buffer . from ( process . env . SAML_CERT , 'base64' ) . toString ( 'utf8' ) ,
11+ privateKey : process . env . SAML_PRIVATE_KEY ? Buffer . from ( process . env . SAML_PRIVATE_KEY , 'base64' ) . toString ( 'utf8' ) : undefined ,
12+ identifierFormat : process . env . SAML_IDENTIFIER_FORMAT || 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' ,
13+ acceptedClockSkewMs : process . env . SAML_ACCEPTED_CLOCK_SKEW_MS ? parseInt ( process . env . SAML_ACCEPTED_CLOCK_SKEW_MS , 10 ) : 5000 ,
14+ signatureAlgorithm : 'sha256' ,
15+ digestAlgorithm : 'sha256' ,
16+ wantAssertionsSigned : true ,
17+ wantAuthnResponseSigned : false ,
18+ } ;
919
10- if ( isSamlAvailable ( ) ) {
11- const samlOptions = {
12- entryPoint : process . env . SAML_ENTRY_POINT ,
13- issuer : process . env . SAML_ISSUER || 'switcher-api' ,
14- callbackUrl : `${ process . env . SAML_CALLBACK_ENDPOINT_URL } /admin/saml/callback` ,
15- idpCert : Buffer . from ( process . env . SAML_CERT , 'base64' ) . toString ( 'utf8' ) ,
16- privateKey : process . env . SAML_PRIVATE_KEY ? Buffer . from ( process . env . SAML_PRIVATE_KEY , 'base64' ) . toString ( 'utf8' ) : undefined ,
17- identifierFormat : process . env . SAML_IDENTIFIER_FORMAT || 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' ,
18- acceptedClockSkewMs : process . env . SAML_ACCEPTED_CLOCK_SKEW_MS ? parseInt ( process . env . SAML_ACCEPTED_CLOCK_SKEW_MS , 10 ) : 5000 ,
19- signatureAlgorithm : 'sha256' ,
20- digestAlgorithm : 'sha256' ,
21- wantAssertionsSigned : true ,
22- wantAuthnResponseSigned : false ,
23- } ;
24-
25- const samlStrategy = new SamlStrategy ( samlOptions , async ( profile , done ) => {
26- try {
27- const userInfo = {
28- id : profile . nameID ,
29- email : profile . email || profile [ 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress' ] ,
30- name : profile . firstName || profile . nameID
31- } ;
32-
33- const { jwt } = await signUpSaml ( userInfo ) ;
34- return done ( null , { token : jwt . token } ) ;
35- } catch ( error ) {
36- Logger . error ( 'SAML Strategy Error Event:' , error ) ;
37- return done ( error ) ;
38- }
39- } ) ;
40-
41- passport . use ( 'saml' , samlStrategy ) ;
42- Logger . info ( 'SSO enabled: SAML strategy configured' ) ;
43- Logger . info ( ` - Entry Point: ${ samlOptions . entryPoint } ` ) ;
44- Logger . info ( ` - Callback URL: ${ samlOptions . callbackUrl } ` ) ;
45- Logger . info ( ` - Issuer: ${ samlOptions . issuer } ` ) ;
46- Logger . info ( ` - Identifier Format: ${ samlOptions . identifierFormat } ` ) ;
47- Logger . info ( ` - Accepted Clock Skew (ms): ${ samlOptions . acceptedClockSkewMs } ` ) ;
48- Logger . info ( ` - Idp Cert: ${ samlOptions . idpCert ? 'Provided' : 'Not Provided' } ` ) ;
49- Logger . info ( ` - Private Key: ${ samlOptions . privateKey ? 'Provided' : 'Not Provided' } ` ) ;
50- }
20+ const samlStrategy = new SamlStrategy ( samlOptions , async ( profile , done ) => {
21+ try {
22+ const userInfo = {
23+ id : profile . nameID ,
24+ email : profile . email || profile [ 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress' ] ,
25+ name : profile . firstName || profile . nameID
26+ } ;
27+
28+ const { jwt } = await signUpSaml ( userInfo ) ;
29+ return done ( null , { token : jwt . token } ) ;
30+ } catch ( error ) {
31+ Logger . error ( 'SAML Strategy Error Event:' , error ) ;
32+ return done ( error ) ;
33+ }
34+ } ) ;
5135
36+ passport . use ( 'saml' , samlStrategy ) ;
37+ Logger . info ( 'SSO enabled: SAML strategy configured' ) ;
38+ Logger . info ( ` - Entry Point: ${ samlOptions . entryPoint } ` ) ;
39+ Logger . info ( ` - Callback URL: ${ samlOptions . callbackUrl } ` ) ;
40+ Logger . info ( ` - Issuer: ${ samlOptions . issuer } ` ) ;
41+ Logger . info ( ` - Identifier Format: ${ samlOptions . identifierFormat } ` ) ;
42+ Logger . info ( ` - Accepted Clock Skew (ms): ${ samlOptions . acceptedClockSkewMs } ` ) ;
43+ Logger . info ( ` - Idp Cert: ${ samlOptions . idpCert ? 'Provided' : 'Not Provided' } ` ) ;
44+ Logger . info ( ` - Private Key: ${ samlOptions . privateKey ? 'Provided' : 'Not Provided' } ` ) ;
0 commit comments