From 4fcbd3bf20b4ebad12d28090b8c6e2c8fc4897f0 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Fri, 29 Jul 2022 08:59:05 +0100 Subject: [PATCH] Support statically configured OIDC clients --- src/matrix/net/OidcApi.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/matrix/net/OidcApi.ts b/src/matrix/net/OidcApi.ts index 5a801952..bdc9352a 100644 --- a/src/matrix/net/OidcApi.ts +++ b/src/matrix/net/OidcApi.ts @@ -53,6 +53,22 @@ function assert(condition: any, message: string): asserts condition { } }; +type IssuerUri = string; +interface ClientConfig { + client_id: string; + client_secret?: string; +} + +// These are statically configured OIDC client IDs for particular issuers: +const clientIds: Record = { + "https://dev-6525741.okta.com/": { + client_id: "0oa5x44w64wpNsxi45d7", + }, + "https://keycloak-oidc.lab.element.dev/realms/master/": { + client_id: "hydrogen-oidc-playground" + }, +}; + export class OidcApi { _issuer: string; _requestFn: RequestFunction; @@ -104,6 +120,13 @@ export class OidcApi { registration(): Promise { if (!this._registrationPromise) { this._registrationPromise = (async () => { + // use static client if available + const authority = `${this.issuer}${this.issuer.endsWith('/') ? '' : '/'}`; + + if (clientIds[authority]) { + return clientIds[authority]; + } + const headers = new Map(); headers.set("Accept", "application/json"); headers.set("Content-Type", "application/json");