From 4352b991bff42ed9ff472d09a132f22701c3ab52 Mon Sep 17 00:00:00 2001 From: MPQ MPQ Date: Wed, 8 Jan 2025 15:52:35 -0500 Subject: [PATCH] feat!: consolidate SSO link creation --- src/adapters/authentication.ts | 36 +++++++++++----------------------- tests/authentication.spec.js | 15 ++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/adapters/authentication.ts b/src/adapters/authentication.ts index 111b6625..86e56a3b 100644 --- a/src/adapters/authentication.ts +++ b/src/adapters/authentication.ts @@ -147,35 +147,21 @@ export async function regenerate( return session; } -export async function sso( - optionals: RoutingOptions = {}, -): Promise { - const session = await new Router() - .get('/registration/sso', optionals) - .then(({ body }) => body); - - identification.session = session; - return session; -} - /** - * Retrieves the SAML link from the SSO configuration - */ -export async function getSAMLLink( - optionals: RoutingOptions = {}, -): Promise { - return await new Router() - .get('/registration/sso/saml', optionals) - .then(({ body }) => body); -} - -/** - * Generates and returns an epicenter URL that will redirect to the SAML url. + * Compute an Epicenter URL string that will redirect to the app's SSO login page. + * SSO login destination configured separately. + * @param protocol The SSO protocol to use. + * @param [optionals] Optional arguments; pass network call options overrides here. + * @returns URL string. GET expects 302 to SSO login destination. + * @example + * const href = epicenter.authAdapter.ssoHref('SAML'); + * Login with SSO */ -export function generateSAMLLINK( +export function ssoHref( + protocol: 'SAML', optionals: RoutingOptions = {}, ): string { - return new Router().getURL('/registration/sso/saml', optionals).toString(); + return new Router().getURL(`/registration/sso/user/${protocol}`, optionals).toString(); } /** diff --git a/tests/authentication.spec.js b/tests/authentication.spec.js index d63675c1..3b714553 100644 --- a/tests/authentication.spec.js +++ b/tests/authentication.spec.js @@ -75,4 +75,19 @@ describe('Authentication', () => { req.method.toUpperCase().should.equal('DELETE'); }); }); + describe('authAdapter.ssoHref', () => { + it('Should accept `protocol`', async() => { + const protocol = 'SAML'; + const href = authAdapter.ssoHref(protocol); + const url = href.split('?')[0]; + url.should.equal(`${config.apiProtocol}://${config.apiHost}/api/v${config.apiVersion}/${ACCOUNT}/${PROJECT}/registration/sso/user/${protocol}`); + }); + it('Should support generic URL options', async() => { + const protocol = 'SAML'; + const href = authAdapter.ssoHref(protocol, GENERIC_OPTIONS); + const url = href.split('?')[0]; + const { server, accountShortName, projectShortName } = GENERIC_OPTIONS; + url.should.equal(`${server}/api/v${config.apiVersion}/${accountShortName}/${projectShortName}/registration/sso/user/${protocol}`); + }); + }); });