mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
fix(core): Redirect user to previous url after SSO signin (#6710)
redirect user to previous url after SSO signin
This commit is contained in:
parent
2a7f5437e6
commit
08331c63fb
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue