From 998d2f49e1d5ab832b54bc8a57a55f5215f81f30 Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Wed, 26 May 2021 14:14:52 +0200 Subject: [PATCH] fix: Remove interaction details from IdpRenderHandler --- .../handler/ForgotPasswordHandler.ts | 7 ++----- src/identity/interaction/util/IdpRenderHandler.ts | 10 ++++------ .../interaction/util/IdpRouteController.ts | 14 ++++++-------- .../interaction/util/InitialInteractionHandler.ts | 1 - .../idp/email-password-interaction/confirm.ejs | 7 +------ .../email-password-interaction/forgotPassword.ejs | 4 ++-- templates/idp/email-password-interaction/login.ejs | 2 +- .../idp/email-password-interaction/register.ejs | 4 ++-- .../handler/ForgotPasswordHandler.test.ts | 10 ++-------- .../interaction/util/IdpRouteController.test.ts | 14 ++++---------- .../util/InitialInteractionHandler.test.ts | 2 -- 11 files changed, 24 insertions(+), 51 deletions(-) diff --git a/src/identity/interaction/email-password/handler/ForgotPasswordHandler.ts b/src/identity/interaction/email-password/handler/ForgotPasswordHandler.ts index ea66130f2..539662f72 100644 --- a/src/identity/interaction/email-password/handler/ForgotPasswordHandler.ts +++ b/src/identity/interaction/email-password/handler/ForgotPasswordHandler.ts @@ -45,14 +45,13 @@ export class ForgotPasswordHandler extends InteractionHttpHandler { } public async handle(input: InteractionHttpHandlerInput): Promise { - const interactionDetails = await input.provider.interactionDetails(input.request, input.response); try { // Validate incoming data const { email } = await getFormDataRequestBody(input.request); assert(typeof email === 'string' && email.length > 0, 'Email required'); await this.resetPassword(email); - await this.sendResponse(input.response, interactionDetails, email); + await this.sendResponse(input.response, email); } catch (err: unknown) { throwIdpInteractionError(err, {}); } @@ -93,15 +92,13 @@ export class ForgotPasswordHandler extends InteractionHttpHandler { /** * Sends a response through the messageRenderHandler. * @param response - HttpResponse to send to. - * @param details - Details of the interaction. * @param email - Will be inserted in `prefilled` for the template. */ - private async sendResponse(response: HttpResponse, details: { uid: string }, email: string): Promise { + private async sendResponse(response: HttpResponse, email: string): Promise { // Send response await this.messageRenderHandler.handleSafe({ response, props: { - details, errorMessage: '', prefilled: { email, diff --git a/src/identity/interaction/util/IdpRenderHandler.ts b/src/identity/interaction/util/IdpRenderHandler.ts index c0648f1d3..a683ba977 100644 --- a/src/identity/interaction/util/IdpRenderHandler.ts +++ b/src/identity/interaction/util/IdpRenderHandler.ts @@ -1,14 +1,12 @@ import { RenderHandler } from '../../../server/util/RenderHandler'; export interface IdpRenderHandlerProps { - details: { - uid: string; - }; - errorMessage: string; - prefilled: Record; + errorMessage?: string; + prefilled?: Record; } /** - * A special Render Handler that renders an IDP form + * A special Render Handler that renders an IDP form. + * Contains an error message if something was wrong and prefilled values for forms. */ export abstract class IdpRenderHandler extends RenderHandler {} diff --git a/src/identity/interaction/util/IdpRouteController.ts b/src/identity/interaction/util/IdpRouteController.ts index f6b209cfe..aed56f47c 100644 --- a/src/identity/interaction/util/IdpRouteController.ts +++ b/src/identity/interaction/util/IdpRouteController.ts @@ -6,8 +6,8 @@ import { IdpInteractionError } from './IdpInteractionError'; import type { IdpRenderHandler } from './IdpRenderHandler'; /** - * Handles an IDP interaction route. All routes need to extract interaction details to render - * the UI and accept a POST request to do some action. + * Handles an IDP interaction route. + * All routes render their UI on a GET and accept POST requests to handle the interaction. */ export class IdpRouteController extends RouterHandler { private readonly renderHandler: IdpRenderHandler; @@ -19,27 +19,25 @@ export class IdpRouteController extends RouterHandler { /** * Calls the renderHandler to render using the given response and props. - * `details` typed as any since the `interactionDetails` output typings are not exposed. */ - private async render(input: InteractionHttpHandlerInput, details: any, errorMessage = '', prefilled = {}): + private async render(input: InteractionHttpHandlerInput, errorMessage = '', prefilled = {}): Promise { return this.renderHandler.handleSafe({ response: input.response, - props: { details, errorMessage, prefilled }, + props: { errorMessage, prefilled }, }); } public async handle(input: InteractionHttpHandlerInput): Promise { - const interactionDetails = await input.provider.interactionDetails(input.request, input.response); if (input.request.method === 'GET') { - await this.render(input, interactionDetails); + await this.render(input); } else if (input.request.method === 'POST') { try { await this.handler.handleSafe(input); } catch (err: unknown) { const errorMessage = isNativeError(err) ? err.message : 'An unknown error occurred'; const prefilled = IdpInteractionError.isInstance(err) ? err.prefilled : {}; - await this.render(input, interactionDetails, errorMessage, prefilled); + await this.render(input, errorMessage, prefilled); } } } diff --git a/src/identity/interaction/util/InitialInteractionHandler.ts b/src/identity/interaction/util/InitialInteractionHandler.ts index e635296cb..8a8b6b43b 100644 --- a/src/identity/interaction/util/InitialInteractionHandler.ts +++ b/src/identity/interaction/util/InitialInteractionHandler.ts @@ -39,7 +39,6 @@ export class InitialInteractionHandler extends InteractionHttpHandler { await this.renderHandlerMap[name].handleSafe({ response, props: { - details: interactionDetails, errorMessage: '', prefilled: {}, }, diff --git a/templates/idp/email-password-interaction/confirm.ejs b/templates/idp/email-password-interaction/confirm.ejs index 4d8a30188..454fd2d6d 100644 --- a/templates/idp/email-password-interaction/confirm.ejs +++ b/templates/idp/email-password-interaction/confirm.ejs @@ -12,13 +12,8 @@

Authorize

diff --git a/templates/idp/email-password-interaction/forgotPassword.ejs b/templates/idp/email-password-interaction/forgotPassword.ejs index fcc0d698a..2c28d6788 100644 --- a/templates/idp/email-password-interaction/forgotPassword.ejs +++ b/templates/idp/email-password-interaction/forgotPassword.ejs @@ -12,7 +12,7 @@

Forgot Password