@@ -15,7 +15,7 @@ limitations under the License.
1515*/
1616
1717import type { RequestFunction } from "../../platform/types/types" ;
18- import type { IURLRouter } from "../../domain/navigation/URLRouter.js " ;
18+ import type { IURLRouter } from "../../domain/navigation/URLRouter" ;
1919import type { SegmentType } from "../../domain/navigation" ;
2020
2121const 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
7665export 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 ( ) ;
0 commit comments