Add support for redirecting to external pages after logout (#7905)
* Add support for redirecting to external pages after logout This is primarily useful for deployments where the account is managed and needs to be logged out in other places too, like an SSO system. See docs for more information. * Add e2e test and fix Windows instructions * Fix performance gathering stats * use logger
This commit is contained in:
2
src/@types/global.d.ts
vendored
2
src/@types/global.d.ts
vendored
@@ -52,6 +52,7 @@ import { ConsoleLogger, IndexedDBLogStore } from "../rageshake/rageshake";
|
||||
import ActiveWidgetStore from "../stores/ActiveWidgetStore";
|
||||
import { Skinner } from "../Skinner";
|
||||
import AutoRageshakeStore from "../stores/AutoRageshakeStore";
|
||||
import { ConfigOptions } from "../SdkConfig";
|
||||
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
|
||||
@@ -62,6 +63,7 @@ declare global {
|
||||
Olm: {
|
||||
init: () => Promise<void>;
|
||||
};
|
||||
mxReactSdkConfig: ConfigOptions;
|
||||
|
||||
// Needed for Safari, unknown to TypeScript
|
||||
webkitAudioContext: typeof AudioContext;
|
||||
|
||||
@@ -58,6 +58,7 @@ import LazyLoadingDisabledDialog from "./components/views/dialogs/LazyLoadingDis
|
||||
import SessionRestoreErrorDialog from "./components/views/dialogs/SessionRestoreErrorDialog";
|
||||
import StorageEvictedDialog from "./components/views/dialogs/StorageEvictedDialog";
|
||||
import { setSentryUser } from "./sentry";
|
||||
import SdkConfig from "./SdkConfig";
|
||||
|
||||
const HOMESERVER_URL_KEY = "mx_hs_url";
|
||||
const ID_SERVER_URL_KEY = "mx_is_url";
|
||||
@@ -845,6 +846,13 @@ export async function onLoggedOut(): Promise<void> {
|
||||
stopMatrixClient();
|
||||
await clearStorage({ deleteEverything: true });
|
||||
LifecycleCustomisations.onLoggedOutAndStorageCleared?.();
|
||||
|
||||
// Do this last so we can make sure all storage has been cleared and all
|
||||
// customisations got the memo.
|
||||
if (SdkConfig.get().logout_redirect_url) {
|
||||
logger.log("Redirecting to external provider to finish logout");
|
||||
window.location.href = SdkConfig.get().logout_redirect_url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,13 +20,17 @@ export interface ISsoRedirectOptions {
|
||||
on_welcome_page?: boolean; // eslint-disable-line camelcase
|
||||
}
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
export interface ConfigOptions {
|
||||
[key: string]: any;
|
||||
|
||||
logout_redirect_url?: string;
|
||||
|
||||
// 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
|
||||
sso_immediate_redirect?: boolean;
|
||||
sso_redirect_options?: ISsoRedirectOptions;
|
||||
}
|
||||
/* eslint-enable camelcase*/
|
||||
|
||||
export const DEFAULTS: ConfigOptions = {
|
||||
// Brand name of the app
|
||||
@@ -56,14 +60,14 @@ export default class SdkConfig {
|
||||
SdkConfig.instance = i;
|
||||
|
||||
// For debugging purposes
|
||||
(<any>window).mxReactSdkConfig = i;
|
||||
window.mxReactSdkConfig = i;
|
||||
}
|
||||
|
||||
static get() {
|
||||
public static get() {
|
||||
return SdkConfig.instance || {};
|
||||
}
|
||||
|
||||
static put(cfg: ConfigOptions) {
|
||||
public static put(cfg: ConfigOptions) {
|
||||
const defaultKeys = Object.keys(DEFAULTS);
|
||||
for (let i = 0; i < defaultKeys.length; ++i) {
|
||||
if (cfg[defaultKeys[i]] === undefined) {
|
||||
@@ -73,11 +77,11 @@ export default class SdkConfig {
|
||||
SdkConfig.setInstance(cfg);
|
||||
}
|
||||
|
||||
static unset() {
|
||||
public static unset() {
|
||||
SdkConfig.setInstance({});
|
||||
}
|
||||
|
||||
static add(cfg: ConfigOptions) {
|
||||
public static add(cfg: ConfigOptions) {
|
||||
const liveConfig = SdkConfig.get();
|
||||
const newConfig = Object.assign({}, liveConfig, cfg);
|
||||
SdkConfig.put(newConfig);
|
||||
|
||||
Reference in New Issue
Block a user