fix: Remove interaction details from IdpRenderHandler

This commit is contained in:
Joachim Van Herwegen
2021-05-26 14:14:52 +02:00
parent 6bfe1bdccc
commit 998d2f49e1
11 changed files with 24 additions and 51 deletions

View File

@@ -45,14 +45,13 @@ export class ForgotPasswordHandler extends InteractionHttpHandler {
}
public async handle(input: InteractionHttpHandlerInput): Promise<void> {
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<void> {
private async sendResponse(response: HttpResponse, email: string): Promise<void> {
// Send response
await this.messageRenderHandler.handleSafe({
response,
props: {
details,
errorMessage: '',
prefilled: {
email,

View File

@@ -1,14 +1,12 @@
import { RenderHandler } from '../../../server/util/RenderHandler';
export interface IdpRenderHandlerProps {
details: {
uid: string;
};
errorMessage: string;
prefilled: Record<string, any>;
errorMessage?: string;
prefilled?: Record<string, any>;
}
/**
* 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<IdpRenderHandlerProps> {}

View File

@@ -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<void> {
return this.renderHandler.handleSafe({
response: input.response,
props: { details, errorMessage, prefilled },
props: { errorMessage, prefilled },
});
}
public async handle(input: InteractionHttpHandlerInput): Promise<void> {
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);
}
}
}

View File

@@ -39,7 +39,6 @@ export class InitialInteractionHandler extends InteractionHttpHandler {
await this.renderHandlerMap[name].handleSafe({
response,
props: {
details: interactionDetails,
errorMessage: '',
prefilled: {},
},