Skip to content

Commit 7d75154

Browse files
committed
Put static OIDC client config into config file
1 parent 0d49c1a commit 7d75154

File tree

5 files changed

+38
-21
lines changed

5 files changed

+38
-21
lines changed

src/domain/login/StartOIDCLoginViewModel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class StartOIDCLoginViewModel extends ViewModel {
3030
encoding: this.platform.encoding,
3131
crypto: this.platform.crypto,
3232
urlRouter: this.urlRouter,
33+
staticClients: this.platform.config["staticOidcClients"],
3334
});
3435
}
3536

src/matrix/Client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export class Client {
137137
request: this._platform.request,
138138
encoding: this._platform.encoding,
139139
crypto: this._platform.crypto,
140+
staticClients: this._platform.config["staticOidcClients"],
140141
});
141142
await oidcApi.validate();
142143

src/matrix/net/OidcApi.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import type {RequestFunction} from "../../platform/types/types";
18-
import type {IURLRouter} from "../../domain/navigation/URLRouter.js";
18+
import type {IURLRouter} from "../../domain/navigation/URLRouter";
1919
import type {SegmentType} from "../../domain/navigation";
2020

2121
const WELL_KNOWN = ".well-known/openid-configuration";
@@ -54,40 +54,34 @@ function assert(condition: any, message: string): asserts condition {
5454
}
5555
};
5656

57-
type IssuerUri = string;
58-
interface ClientConfig {
57+
export type IssuerUri = string;
58+
59+
export interface OidcClientConfig {
5960
client_id: string;
60-
client_secret?: string;
6161
}
6262

63-
// These are statically configured OIDC client IDs for particular issuers:
64-
const clientIds: Record<IssuerUri, ClientConfig> = {
65-
"https://dev-6525741.okta.com/": {
66-
client_id: "0oa5x44w64wpNsxi45d7",
67-
},
68-
"https://keycloak-oidc.lab.element.dev/realms/master/": {
69-
client_id: "hydrogen-oidc-playground"
70-
},
71-
"https://id.thirdroom.io/realms/thirdroom/": {
72-
client_id: "hydrogen-oidc-playground"
73-
},
74-
};
63+
export type StaticOidcClientsConfig = Record<IssuerUri, OidcClientConfig>;
7564

7665
export class OidcApi<N extends object = SegmentType> {
77-
_issuer: string;
66+
_issuer: IssuerUri;
7867
_requestFn: RequestFunction;
7968
_encoding: any;
8069
_crypto: any;
8170
_urlRouter: IURLRouter<N>;
8271
_metadataPromise: Promise<any>;
8372
_registrationPromise: Promise<any>;
73+
_staticClients: StaticOidcClientsConfig;
8474

85-
constructor({ issuer, request, encoding, crypto, urlRouter, clientId }) {
75+
constructor({ issuer, request, encoding, crypto, urlRouter, clientId, staticClients = {} }: { issuer: IssuerUri, request: RequestFunction, encoding: any, crypto: any, urlRouter: IURLRouter<N>, clientId?: string, staticClients?: StaticOidcClientsConfig}) {
8676
this._issuer = issuer;
8777
this._requestFn = request;
8878
this._encoding = encoding;
8979
this._crypto = crypto;
9080
this._urlRouter = urlRouter;
81+
this._staticClients = staticClients;
82+
83+
console.log(staticClients);
84+
console.log(clientId);
9185

9286
if (clientId) {
9387
this._registrationPromise = Promise.resolve({ client_id: clientId });
@@ -127,8 +121,8 @@ export class OidcApi<N extends object = SegmentType> {
127121
// use static client if available
128122
const authority = `${this.issuer}${this.issuer.endsWith('/') ? '' : '/'}`;
129123

130-
if (clientIds[authority]) {
131-
return clientIds[authority];
124+
if (this._staticClients[authority]) {
125+
return this._staticClients[authority];
132126
}
133127

134128
const headers = new Map();

src/platform/types/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
import type { StaticOidcClientsConfig } from "../../matrix/net/OidcApi";
18+
1719
export type Config = {
1820
/**
1921
* The default homeserver used by Hydrogen; auto filled in the login UI.
@@ -61,4 +63,12 @@ export type Config = {
6163
// See pushkey in above link
6264
applicationServerKey: string;
6365
};
66+
67+
/**
68+
* Configuration for OIDC issuers where a static client_id has been issued for the app.
69+
* Otherwise dynamic client registration is attempted.
70+
* The issuer URL must have a trailing `/`.
71+
* OPTIONAL
72+
*/
73+
staticOidcClients?: StaticOidcClientsConfig;
6474
};

src/platform/web/assets/config.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,16 @@
55
"applicationServerKey": "BC-gpSdVHEXhvHSHS0AzzWrQoukv2BE7KzpoPO_FfPacqOo3l1pdqz7rSgmB04pZCWaHPz7XRe6fjLaC-WPDopM"
66
},
77
"defaultHomeServer": "matrix.org",
8-
"bugReportEndpointUrl": "https://element.io/bugreports/submit"
8+
"bugReportEndpointUrl": "https://element.io/bugreports/submit",
9+
"staticOidcClients": {
10+
"https://dev-6525741.okta.com/": {
11+
"client_id": "0oa5x44w64wpNsxi45d7"
12+
},
13+
"https://keycloak-oidc.lab.element.dev/realms/master/": {
14+
"client_id": "hydrogen-oidc-playground"
15+
},
16+
"https://id.thirdroom.io/realms/thirdroom/": {
17+
"client_id": "hydrogen-oidc-playground"
18+
}
19+
}
920
}

0 commit comments

Comments
 (0)