Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
flipswitchingmonkey committed Apr 14, 2023
1 parent 73d5ecc commit 049ce79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/cli/src/sso/saml/routes/saml.controller.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getInitSSOFormView } from '../views/initSsoPost';
import { issueCookie } from '@/auth/jwt';
import { validate } from 'class-validator';
import type { PostBindingContext } from 'samlify/types/src/entity';
import { isSamlLicensedAndEnabled } from '../samlHelpers';
import { isConnectionTestRequest, isSamlLicensedAndEnabled } from '../samlHelpers';
import type { SamlLoginBinding } from '../types';
import { AuthenticatedRequest } from '@/requests';
import {
Expand Down Expand Up @@ -111,7 +111,7 @@ export class SamlController {
try {
const loginResult = await this.samlService.handleSamlLogin(req, binding);
// if RelayState is set to the test connection Url, this is a test connection
if (req.body.RelayState && req.body.RelayState === getServiceProviderConfigTestReturnUrl()) {
if (isConnectionTestRequest(req)) {
if (loginResult.authenticatedUser) {
return res.send(getSamlConnectionTestSuccessView(loginResult.attributes));
} else {
Expand All @@ -133,7 +133,7 @@ export class SamlController {
}
throw new AuthError('SAML Authentication failed');
} catch (err) {
if (req.body.RelayState && req.body.RelayState === getServiceProviderConfigTestReturnUrl()) {
if (isConnectionTestRequest(req)) {
return res.send(getSamlConnectionTestFailedView(err.message));
}
throw new AuthError('SAML Authentication failed: ' + err.message);
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/sso/saml/samlHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
isSamlCurrentAuthenticationMethod,
setCurrentAuthenticationMethod,
} from '../ssoHelpers';
import { getServiceProviderConfigTestReturnUrl } from './serviceProvider.ee';
import { SamlConfiguration } from './types/requests';
/**
* Check whether the SAML feature is licensed and enabled in the instance
*/
Expand Down Expand Up @@ -173,3 +175,7 @@ export function getMappedSamlAttributesFromFlowResult(
}
return result;
}

export function isConnectionTestRequest(req: SamlConfiguration.AcsRequest): boolean {
return req.body.RelayState === getServiceProviderConfigTestReturnUrl();
}

0 comments on commit 049ce79

Please sign in to comment.