loopbackio / loopbackio/loopback-next
Allow middleware to redirect without the controller being involved.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 5.1k
- Forks
- 1.1k
- Ø Merge
- 2 T. 21 Std.
- Gemergte PRs (30 T.)
- 27
Beschreibung
Suggestion
It would appear that today if some middleware logic wishes to send a redirect response, the controller must be aware of that and handle the redirection on behalf of the middleware. This seems a bit incoherent, as the controller is generally concerned with managing the resource defined by the REST endpoint, and not the needs of the middleware.
Use Cases
Authentication. See this example. Why do I need special controller logic for loginToThirdParty there? If the middleware abstraction weren't leaking, I'd expect that I could just decorate any endpoint method of my controller with @authenticate(STRATEGY_NAME) and if the strategy requires redirection (e.g. OIDC), the user should be redirected to login/grant access, then redirected back to the endpoint in question. If I want to enable this behaviour today it would appear that I need this redirection logic for every single protected controller function that I write.
Examples
One way to achieve this would be to follow the pattern that AuthenticationActionProvider uses here, but instead of writing to setters that are bound to a binding specific to the Authentication namespace, write to some more generic binding that can be picked up and handled before the controller is ever called, subverting the need to call the controller entirely.
Another way might be to inspect the return value of the middleware. If it returns a RedirectRoute, redirect instead of calling the controller. I find this to be a cleaner option than injecting setters, but I can imagine this being more difficult to implement. As an aside, it'd be nice if controllers could do this as well, rather than requiring the Response object to be injected.
Acceptance criteria
TBD - will be filled by the team.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, packages/authentication/src/providers/auth-action.provider.ts in der Nähe der referenzierten Zeilen zu überprüfen, und verfolge anschließend, wie Middleware-Ergebnisse und der Aufruf des Controllers verarbeitet werden. Vergleiche die vorgeschlagenen binding-basierten und RedirectRoute-Ansätze; die Akzeptanzkriterien des Issues sind weiterhin TBD, daher muss das Team das erwartete Verhalten festlegen, bevor die Implementierung als abgeschlossen gelten kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- api, backend-api-design
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100