@@ -11,6 +11,7 @@ import {
1111 ValidateSession ,
1212 getIdToken ,
1313} from '../../lib/auth'
14+ import querystring from 'querystring'
1415
1516export default function Login ( props ) {
1617 const router = useRouter ( )
@@ -29,8 +30,18 @@ export default function Login(props) {
2930 return
3031 }
3132
32- const redirectTarget = props . redirectUrl
33- ? props . ecasUrl + props . redirectUrl
33+ const redirectLang = props . locale === 'en' ? 'eng' : 'fra'
34+ const queryLangParam = new URLSearchParams ( props . redirectQueryString ) . get (
35+ 'Lang' ,
36+ )
37+ const langParam = queryLangParam ? '' : '&Lang=' + redirectLang
38+ const curamRedirect =
39+ props . ecasUrl +
40+ '/ecas-seca/rascl_iv/Curam/SAMLIdentityProvider.aspx?' +
41+ props . redirectQueryString +
42+ langParam
43+ const redirectTarget = props . redirectQueryString
44+ ? curamRedirect
3445 : props . locale === 'en'
3546 ? `${ window . location . origin } /api/welcome?locale=en`
3647 : `${ window . location . origin } /api/welcome?locale=fr`
@@ -68,7 +79,7 @@ export async function getServerSideProps({ req, res, locale, query }) {
6879 const token = await getIdToken ( req )
6980 const ecasUrl = process . env . AUTH_ECAS_BASE_URL
7081 // TODO: Compare vs a whitelist
71- const queryRedirect = query . endpoint ? query . endpoint : ''
82+ const queryRedirect = query . link ? querystring . stringify ( query ) : ''
7283
7384 //If Next-Auth session is valid, check to see if ECAS session is and then redirect to dashboard instead of reinitiating auth
7485 if ( ! AuthIsDisabled ( ) && ( await AuthIsValid ( req , session ) ) ) {
@@ -88,20 +99,20 @@ export async function getServerSideProps({ req, res, locale, query }) {
8899 }
89100
90101 // If we get into the flow above and are already logged in, ignore redirect
91- let redirectUrl = ''
102+ let redirectQueryString = ''
92103 const isSecure = req . headers [ 'x-forwarded-proto' ] === 'https'
93104 if ( queryRedirect ) {
94105 // If there's a query parameter, it overrides any cookies
95106 res . setHeader (
96107 'Set-Cookie' ,
97- `redirecturl =${ queryRedirect } ; max-age=900; path=/; samesite=strict ; HttpOnly; ${ isSecure ? 'Secure;' : '' } ` ,
108+ `redirectquery =${ queryRedirect } ; max-age=900; path=/; samesite=strict ; HttpOnly; ${ isSecure ? 'Secure;' : '' } ` ,
98109 )
99- redirectUrl = queryRedirect
110+ redirectQueryString = queryRedirect
100111 } else {
101- const redirectCookie = req . cookies . redirecturl
112+ const redirectCookie = req . cookies . redirectquery
102113 if ( redirectCookie ) {
103114 // If there's no query parameter, set to the redirect cookie value
104- redirectUrl = redirectCookie
115+ redirectQueryString = redirectCookie
105116 }
106117 // If there's no query paramater AND no cookie, return empty to trigger normal flow
107118 }
@@ -133,7 +144,7 @@ export async function getServerSideProps({ req, res, locale, query }) {
133144 locale,
134145 meta,
135146 authDisabled : authDisabled ?? true ,
136- redirectUrl : redirectUrl ,
147+ redirectQueryString : redirectQueryString ,
137148 ecasUrl : ecasUrl ,
138149 } ,
139150 }
0 commit comments