Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Allow explicit configuration of OIDC dynamic registration metadata #12514

Merged
merged 12 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/BasePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,23 +430,31 @@ export default abstract class BasePlatform {
return window.location.origin + window.location.pathname;
}

/**
* Fallback Client URI to use for OIDC client registration for if one is not specified in config.json
*/
public get defaultOidcClientUri(): string {
return window.location.origin;
}

/**
* Metadata to use for dynamic OIDC client registrations
*/
public async getOidcClientMetadata(): Promise<OidcRegistrationClientMetadata> {
const config = SdkConfig.get();
return {
clientName: config.brand,
clientUri: this.baseUrl,
clientUri: config.oidc_metadata?.client_uri ?? this.defaultOidcClientUri,
redirectUris: [this.getOidcCallbackUrl().href],
logoUri: new URL("vector-icons/1024.png", this.baseUrl).href,
logoUri: config.oidc_metadata?.logo_uri ?? new URL("vector-icons/1024.png", this.baseUrl).href,
applicationType: "web",
// XXX: We break the spec by not consistently supplying these required fields
// contacts: [],
// @ts-ignore
tosUri: config.terms_and_conditions_links?.[0]?.url,
contacts: config.oidc_metadata?.contacts,
// @ts-ignore
tosUri: config.oidc_metadata?.tos_uri ?? config.terms_and_conditions_links?.[0]?.url,
// @ts-ignore
policyUri: config.privacy_policy_url,
policyUri: config.oidc_metadata?.policy_uri ?? config.privacy_policy_url,
};
}

Expand Down
20 changes: 14 additions & 6 deletions src/IConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,20 @@ export interface IConfigOptions {
* The issuer URL must have a trailing `/`.
* OPTIONAL
*/
oidc_static_clients?: Record<
string,
{
client_id: string;
}
>;
oidc_static_clients?: {
[issuer: string]: { client_id: string };
};

/**
* Configuration for OIDC dynamic registration where a static OIDC client is not configured.
*/
oidc_metadata?: {
client_uri?: string;
logo_uri?: string;
tos_uri?: string;
policy_uri?: string;
contacts?: string[];
};
}

export interface ISsoRedirectOptions {
Expand Down
5 changes: 5 additions & 0 deletions test/utils/oidc/registerClient-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ describe("getOidcClientId()", () => {
return baseUrl;
},
});
Object.defineProperty(PlatformPeg.get(), "defaultOidcClientUri", {
get(): string {
return baseUrl;
},
});
Object.defineProperty(PlatformPeg.get(), "getOidcCallbackUrl", {
value: () => ({
href: baseUrl,
Expand Down
Loading