Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions src/adapters/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,21 @@ export async function regenerate(
return session;
}

export async function sso(
optionals: RoutingOptions = {},
): Promise<Session> {
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<string> {
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');
* <a href={href}>Login with SSO</a>
*/
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();
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/authentication.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
});
});