fix(core): Redirect user to previous url after SSO signin (#6710)

redirect user to previous url after SSO signin
This commit is contained in:
Michael Auerswald 2023-07-20 17:23:29 +02:00 committed by GitHub
parent 2a7f5437e6
commit 08331c63fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View file

@ -25,6 +25,8 @@ import {
import { getSamlConnectionTestSuccessView } from '../views/samlConnectionTestSuccess';
import { getSamlConnectionTestFailedView } from '../views/samlConnectionTestFailed';
import { InternalHooks } from '@/InternalHooks';
import url from 'url';
import querystring from 'querystring';
@Service()
@RestController('/sso/saml')
@ -138,7 +140,8 @@ export class SamlController {
if (loginResult.onboardingRequired) {
return res.redirect(getInstanceBaseUrl() + SamlUrls.samlOnboarding);
} else {
return res.redirect(getInstanceBaseUrl() + SamlUrls.defaultRedirect);
const redirectUrl = req.body?.RelayState ?? SamlUrls.defaultRedirect;
return res.redirect(getInstanceBaseUrl() + redirectUrl);
}
} else {
return res.status(202).send(loginResult.attributes);
@ -169,7 +172,22 @@ export class SamlController {
@NoAuthRequired()
@Get(SamlUrls.initSSO, { middlewares: [samlLicensedAndEnabledMiddleware] })
async initSsoGet(req: express.Request, res: express.Response) {
return this.handleInitSSO(res);
let redirectUrl = '';
try {
const refererUrl = req.headers.referer;
if (refererUrl) {
const parsedUrl = url.parse(refererUrl);
if (parsedUrl?.query) {
const parsedQueryParams = querystring.parse(parsedUrl.query);
if (parsedQueryParams.redirect && typeof parsedQueryParams.redirect === 'string') {
redirectUrl = querystring.unescape(parsedQueryParams.redirect);
}
}
}
} catch {
// ignore
}
return this.handleInitSSO(res, redirectUrl);
}
/**

View file

@ -140,8 +140,6 @@ export class SamlService {
const sp = this.getServiceProviderInstance();
sp.entitySetting.relayState = relayState ?? getInstanceBaseUrl();
const loginRequest = sp.createLoginRequest(this.getIdentityProviderInstance(), 'redirect');
//TODO:SAML: debug logging
LoggerProxy.debug(loginRequest.context);
return loginRequest;
}
@ -152,8 +150,6 @@ export class SamlService {
this.getIdentityProviderInstance(),
'post',
) as PostBindingContext;
//TODO:SAML: debug logging
LoggerProxy.debug(loginRequest.context);
return loginRequest;
}