fix: Rewrite request with a root path to OIDC Provider

* fix(oidc): rewrite requests with rootpath

* fix: respect query parameters
This commit is contained in:
Jasper Vaneessen
2022-05-18 09:42:01 +02:00
committed by GitHub
parent e7ba2d49f8
commit 0a84230307
3 changed files with 34 additions and 4 deletions

View File

@@ -18,6 +18,13 @@ export class OidcHttpHandler extends HttpHandler {
public async handle({ request, response }: HttpHandlerInput): Promise<void> {
const provider = await this.providerFactory.getProvider();
// Rewrite requests to allow hosting on root paths
const path = new URL(provider.issuer).pathname;
if (path.length > 1 && request.url!.startsWith(`${path}.well-known/openid-configuration`)) {
request.url = request.url!.replace(path, '/');
}
this.logger.debug(`Sending request to oidc-provider: ${request.url}`);
// Even though the typings do not indicate this, this is a Promise that needs to be awaited.
// Otherwise, the `BaseHttpServerFactory` will write a 404 before the OIDC library could handle the response.