From bc32f05fcbfb2f6c2219d3ad840ef20ca1749177 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 21 Oct 2021 08:35:00 -0600 Subject: [PATCH] Add config types and utility function for SSO redirect config (#6976) * Add config types and utility function for SSO redirect config * Appease the linter --- src/SdkConfig.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/SdkConfig.ts b/src/SdkConfig.ts index 7d7caa2d24..af2a706aaa 100644 --- a/src/SdkConfig.ts +++ b/src/SdkConfig.ts @@ -1,6 +1,6 @@ /* Copyright 2016 OpenMarket Ltd -Copyright 2019, 2020 The Matrix.org Foundation C.I.C. +Copyright 2019 - 2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,8 +15,17 @@ See the License for the specific language governing permissions and limitations under the License. */ +export interface ISsoRedirectOptions { + immediate?: boolean; + on_welcome_page?: boolean; // eslint-disable-line camelcase +} + export interface ConfigOptions { [key: string]: any; + + // sso_immediate_redirect is deprecated in favour of sso_redirect_options.immediate + sso_immediate_redirect?: boolean; // eslint-disable-line camelcase + sso_redirect_options?: ISsoRedirectOptions; // eslint-disable-line camelcase } export const DEFAULTS: ConfigOptions = { @@ -74,3 +83,14 @@ export default class SdkConfig { SdkConfig.put(newConfig); } } + +export function parseSsoRedirectOptions(config: ConfigOptions): ISsoRedirectOptions { + // Ignore deprecated options if the config is using new ones + if (config.sso_redirect_options) return config.sso_redirect_options; + + // We can cheat here because the default is false anyways + if (config.sso_immediate_redirect) return { immediate: true }; + + // Default: do nothing + return {}; +}