11import bodyParser from 'body-parser' ;
2+ import cookieParser from 'cookie-parser' ;
23import envConfig from './envConfig.js' ;
34import express from 'express' ;
45import { getCloudServices } from '../container/CloudServicesRegistry.js' ;
@@ -48,6 +49,10 @@ export const expressConfiguration = (app: express.Express) => {
4849 app . use ( permissionsPolicy ( ) ) ;
4950 app . use ( nocache ( ) ) ;
5051
52+ app . use ( bodyParser . json ( { type : 'application/json' } ) ) ;
53+ app . use ( cookieParser ( ) ) ;
54+ app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
55+
5156 app . use (
5257 session ( {
5358 secret : envConfig . sessionSecret ,
@@ -65,14 +70,25 @@ export const expressConfiguration = (app: express.Express) => {
6570
6671 app . post (
6772 '/login/callback' ,
68- bodyParser . urlencoded ( { extended : false } ) ,
6973 passport . authenticate ( 'saml' , {
7074 failureRedirect : '/' ,
7175 failureFlash : true ,
7276 } ) ,
7377 function ( req , res ) {
74- const redirectUrl = decodeURIComponent ( req . body . RelayState ) ;
75- logger . debug ( `Redirect to: ${ redirectUrl } ` ) ;
78+ // Handle RelayState from either body or query parameters, with fallback to session
79+ const relayState = req . body ?. RelayState || req . query ?. RelayState || req . session ?. returnTo ;
80+ const redirectUrl = relayState ? decodeURIComponent ( relayState ) : '/' ;
81+
82+ logger . debug ( `SAML callback - RelayState: ${ relayState } , Redirect to: ${ redirectUrl } ` ) ;
83+ logger . debug ( `Request body:` , req . body ) ;
84+ logger . debug ( `Request query:` , req . query ) ;
85+ logger . debug ( `Session returnTo:` , req . session ?. returnTo ) ;
86+
87+ // Clear the returnTo from session after using it
88+ if ( req . session ?. returnTo ) {
89+ delete req . session . returnTo ;
90+ }
91+
7692 res . redirect ( redirectUrl ) ;
7793 } ,
7894 ) ;
0 commit comments