Merge pull request #16880 from vector-im/travis/sso-redirect-auto

Support a config option to skip login/welcome and go to SSO
This commit is contained in:
Travis Ralston 2021-04-07 07:40:50 -06:00 committed by GitHub
commit 040058957f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -35,6 +35,7 @@ import SdkConfig from "matrix-react-sdk/src/SdkConfig";
import {parseQs, parseQsFromFragment} from './url_utils';
import VectorBasePlatform from "./platform/VectorBasePlatform";
import {createClient} from "matrix-js-sdk/src/matrix";
let lastLocationHashSet: string = null;
@ -153,6 +154,26 @@ export async function loadApp(fragParams: {}) {
// Don't bother loading the app until the config is verified
const config = await verifyServerConfig();
// Before we continue, let's see if we're supposed to do an SSO redirect
const [userId] = await Lifecycle.getStoredSessionOwner();
const hasPossibleToken = !!userId;
const isReturningFromSso = !!params.loginToken;
const autoRedirect = config['sso_immediate_redirect'] === true;
if (!hasPossibleToken && !isReturningFromSso && autoRedirect) {
console.log("Bypassing app load to redirect to SSO");
const tempCli = createClient({
baseUrl: config['validated_server_config'].hsUrl,
idBaseUrl: config['validated_server_config'].isUrl,
});
PlatformPeg.get().startSingleSignOn(tempCli, "sso", `/${getScreenFromLocation(window.location).screen}`);
// We return here because startSingleSignOn() will asynchronously redirect us. We don't
// care to wait for it, and don't want to show any UI while we wait (not even half a welcome
// page). As such, just don't even bother loading the MatrixChat component.
return;
}
const MatrixChat = sdk.getComponent('structures.MatrixChat');
return <MatrixChat
onNewScreen={onNewScreen}