docs: Explain why IDP redirects are transformed into JSON responses.

This commit is contained in:
Ruben Verborgh 2022-02-23 10:40:14 +01:00
parent f3e23ce667
commit eceb71088a
2 changed files with 15 additions and 7 deletions

View File

@ -27,7 +27,7 @@
] ]
}, },
{ {
"comment": "Converts redirect errors to location JSON responses.", "comment": "Converts 3xx redirects to 200 JSON responses for consumption by browser scripts.",
"@id": "urn:solid-server:auth:password:LocationInteractionHandler", "@id": "urn:solid-server:auth:password:LocationInteractionHandler",
"@type": "LocationInteractionHandler", "@type": "LocationInteractionHandler",
"LocationInteractionHandler:_source" : { "@id": "urn:solid-server:auth:password:InteractionRouteHandler" } "LocationInteractionHandler:_source" : { "@id": "urn:solid-server:auth:password:InteractionRouteHandler" }

View File

@ -6,13 +6,21 @@ import type { InteractionHandlerInput } from './InteractionHandler';
import { InteractionHandler } from './InteractionHandler'; import { InteractionHandler } from './InteractionHandler';
/** /**
* Catches redirect errors from the source and returns a JSON body containing a `location` field instead. * Transforms an HTTP redirect into a hypermedia document with a redirection link,
* This allows the API to be used more easily from the browser. * such that scripts running in a browser can redirect the user to the next page.
* *
* The issue is that if the API actually did a redirect, * This handler addresses the situation where:
* this would make it unusable when using it on HTML pages that need to render errors in case the fetch fails, * - the user visits a first page
* but want to redirect the page in case it succeeds. * - this first page contains a script that performs interactions with a JSON API
* See full overview at https://github.com/solid/community-server/pull/1088. * - as a result of a certain interaction, the user needs to be redirected to a second page
*
* Regular HTTP redirects are performed via responses with 3xx status codes.
* However, since the consumer of the API in this case is a browser script,
* a 3xx response would only reach that script and not move the page for the user.
*
* Therefore, this handler changes a 3xx response into a 200 response
* with an explicit link to the next page,
* enabling the script to move the user to the next page.
*/ */
export class LocationInteractionHandler extends InteractionHandler { export class LocationInteractionHandler extends InteractionHandler {
private readonly source: InteractionHandler; private readonly source: InteractionHandler;