Skip to content

Commit

Permalink
feat(authentication): redirect after first authentication step instea…
Browse files Browse the repository at this point in the history
…d of returning the url (#508)
  • Loading branch information
ghusse authored and Guillaume Gautreau committed Nov 24, 2020
1 parent d5a98b2 commit be4e1e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/routes/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ async function startAuthentication(context, request, response, next) {
const renderingId = getAndCheckRenderingId(request, context);

const originalUrl = context.requestAnalyzerService.extractOriginalUrlWithoutQuery(request);
response.json(
await context.authenticationService.startAuthentication(
`${originalUrl}/callback`,
{ renderingId },
),
const result = await context.authenticationService.startAuthentication(
`${originalUrl}/callback`,
{ renderingId },
);

response.redirect(result.authorizationUrl);
} catch (e) {
next(e);
}
Expand Down Expand Up @@ -130,4 +130,5 @@ function initAuthenticationRoutes(
}

initAuthenticationRoutes.PUBLIC_ROUTES = PUBLIC_ROUTES;
initAuthenticationRoutes.CALLBACK_ROUTE = CALLBACK_AUTHENTICATION_ROUTE;
module.exports = initAuthenticationRoutes;
18 changes: 8 additions & 10 deletions test/routes/authentication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,14 @@ describe('routes > authentication', () => {
const expectedScope = 'openid email profile';
const expectedCallback = `${test.url}/callback`;

expect(receivedResponse.status).toBe(200);
expect(JSON.parse(receivedResponse.text)).toStrictEqual({
authorizationUrl: `https://app.forestadmin.com/oidc/authorization?client_id=${
encodeURI(expectedId)
}&scope=${
encodeURIComponent(expectedScope)
}&response_type=code&redirect_uri=${
encodeURIComponent(expectedCallback)
}&state=${encodeURIComponent(JSON.stringify({ renderingId: 42 }))}`,
});
expect(receivedResponse.status).toBe(302);
expect(receivedResponse.headers.location).toStrictEqual(`https://app.forestadmin.com/oidc/authorization?client_id=${
encodeURI(expectedId)
}&scope=${
encodeURIComponent(expectedScope)
}&response_type=code&redirect_uri=${
encodeURIComponent(expectedCallback)
}&state=${encodeURIComponent(JSON.stringify({ renderingId: 42 }))}`);
} finally {
sandbox.restore();
}
Expand Down

0 comments on commit be4e1e4

Please sign in to comment.