mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 11:47:23 +03:00
Move to mx_sso_hs_url and co for sso persistance to not conflict with guest creds
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
3524d678f7
commit
1c00ae8dd3
3 changed files with 17 additions and 19 deletions
|
@ -25,8 +25,8 @@ import {CheckUpdatesPayload} from "./dispatcher/payloads/CheckUpdatesPayload";
|
||||||
import {Action} from "./dispatcher/actions";
|
import {Action} from "./dispatcher/actions";
|
||||||
import {hideToast as hideUpdateToast} from "./toasts/UpdateToast";
|
import {hideToast as hideUpdateToast} from "./toasts/UpdateToast";
|
||||||
|
|
||||||
export const HOMESERVER_URL_KEY = "mx_hs_url";
|
export const SSO_HOMESERVER_URL_KEY = "mx_sso_hs_url";
|
||||||
export const ID_SERVER_URL_KEY = "mx_is_url";
|
export const SSO_ID_SERVER_URL_KEY = "mx_sso_is_url";
|
||||||
|
|
||||||
export enum UpdateCheckStatus {
|
export enum UpdateCheckStatus {
|
||||||
Checking = "CHECKING",
|
Checking = "CHECKING",
|
||||||
|
@ -221,21 +221,12 @@ export default abstract class BasePlatform {
|
||||||
|
|
||||||
setLanguage(preferredLangs: string[]) {}
|
setLanguage(preferredLangs: string[]) {}
|
||||||
|
|
||||||
getSSOCallbackUrl(fragmentAfterLogin: string): URL {
|
protected getSSOCallbackUrl(fragmentAfterLogin: string): URL {
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
url.hash = fragmentAfterLogin || "";
|
url.hash = fragmentAfterLogin || "";
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// persist hs url and is url for when the user is returned to the app with the login token
|
|
||||||
// MUST be called before using URLs from getSSOCallbackUrl, internally called by startSingleSignOn
|
|
||||||
persistSSODetails(mxClient: MatrixClient) {
|
|
||||||
localStorage.setItem(HOMESERVER_URL_KEY, mxClient.getHomeserverUrl());
|
|
||||||
if (mxClient.getIdentityServerUrl()) {
|
|
||||||
localStorage.setItem(ID_SERVER_URL_KEY, mxClient.getIdentityServerUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begin Single Sign On flows.
|
* Begin Single Sign On flows.
|
||||||
* @param {MatrixClient} mxClient the matrix client using which we should start the flow
|
* @param {MatrixClient} mxClient the matrix client using which we should start the flow
|
||||||
|
@ -243,7 +234,11 @@ export default abstract class BasePlatform {
|
||||||
* @param {string} fragmentAfterLogin the hash to pass to the app during sso callback.
|
* @param {string} fragmentAfterLogin the hash to pass to the app during sso callback.
|
||||||
*/
|
*/
|
||||||
startSingleSignOn(mxClient: MatrixClient, loginType: "sso" | "cas", fragmentAfterLogin: string) {
|
startSingleSignOn(mxClient: MatrixClient, loginType: "sso" | "cas", fragmentAfterLogin: string) {
|
||||||
this.persistSSODetails(mxClient);
|
// persist hs url and is url for when the user is returned to the app with the login token
|
||||||
|
localStorage.setItem(SSO_HOMESERVER_URL_KEY, mxClient.getHomeserverUrl());
|
||||||
|
if (mxClient.getIdentityServerUrl()) {
|
||||||
|
localStorage.setItem(SSO_ID_SERVER_URL_KEY, mxClient.getIdentityServerUrl());
|
||||||
|
}
|
||||||
const callbackUrl = this.getSSOCallbackUrl(fragmentAfterLogin);
|
const callbackUrl = this.getSSOCallbackUrl(fragmentAfterLogin);
|
||||||
window.location.href = mxClient.getSsoLoginUrl(callbackUrl.toString(), loginType); // redirect to SSO
|
window.location.href = mxClient.getSsoLoginUrl(callbackUrl.toString(), loginType); // redirect to SSO
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,10 @@ import {IntegrationManagers} from "./integrations/IntegrationManagers";
|
||||||
import {Mjolnir} from "./mjolnir/Mjolnir";
|
import {Mjolnir} from "./mjolnir/Mjolnir";
|
||||||
import DeviceListener from "./DeviceListener";
|
import DeviceListener from "./DeviceListener";
|
||||||
import {Jitsi} from "./widgets/Jitsi";
|
import {Jitsi} from "./widgets/Jitsi";
|
||||||
import {HOMESERVER_URL_KEY, ID_SERVER_URL_KEY} from "./BasePlatform";
|
import {SSO_HOMESERVER_URL_KEY, SSO_ID_SERVER_URL_KEY} from "./BasePlatform";
|
||||||
|
|
||||||
|
export const HOMESERVER_URL_KEY = "mx_hs_url";
|
||||||
|
export const ID_SERVER_URL_KEY = "mx_is_url";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called at startup, to attempt to build a logged-in Matrix session. It tries
|
* Called at startup, to attempt to build a logged-in Matrix session. It tries
|
||||||
|
@ -164,8 +167,8 @@ export function attemptTokenLogin(queryParams, defaultDeviceDisplayName) {
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const homeserver = localStorage.getItem(HOMESERVER_URL_KEY);
|
const homeserver = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
|
||||||
const identityServer = localStorage.getItem(ID_SERVER_URL_KEY);
|
const identityServer = localStorage.getItem(SSO_ID_SERVER_URL_KEY);
|
||||||
if (!homeserver) {
|
if (!homeserver) {
|
||||||
console.warn("Cannot log in with token: can't determine HS URL to use");
|
console.warn("Cannot log in with token: can't determine HS URL to use");
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
|
|
|
@ -25,7 +25,7 @@ import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
||||||
import {sendLoginRequest} from "../../../Login";
|
import {sendLoginRequest} from "../../../Login";
|
||||||
import AuthPage from "../../views/auth/AuthPage";
|
import AuthPage from "../../views/auth/AuthPage";
|
||||||
import SSOButton from "../../views/elements/SSOButton";
|
import SSOButton from "../../views/elements/SSOButton";
|
||||||
import {HOMESERVER_URL_KEY, ID_SERVER_URL_KEY} from "../../../BasePlatform";
|
import {SSO_HOMESERVER_URL_KEY, SSO_ID_SERVER_URL_KEY} from "../../../BasePlatform";
|
||||||
|
|
||||||
const LOGIN_VIEW = {
|
const LOGIN_VIEW = {
|
||||||
LOADING: 1,
|
LOADING: 1,
|
||||||
|
@ -158,8 +158,8 @@ export default class SoftLogout extends React.Component {
|
||||||
async trySsoLogin() {
|
async trySsoLogin() {
|
||||||
this.setState({busy: true});
|
this.setState({busy: true});
|
||||||
|
|
||||||
const hsUrl = localStorage.getItem(HOMESERVER_URL_KEY);
|
const hsUrl = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
|
||||||
const isUrl = localStorage.getItem(ID_SERVER_URL_KEY) || MatrixClientPeg.get().getIdentityServerUrl();
|
const isUrl = localStorage.getItem(SSO_ID_SERVER_URL_KEY) || MatrixClientPeg.get().getIdentityServerUrl();
|
||||||
const loginType = "m.login.token";
|
const loginType = "m.login.token";
|
||||||
const loginParams = {
|
const loginParams = {
|
||||||
token: this.props.realQueryParams['loginToken'],
|
token: this.props.realQueryParams['loginToken'],
|
||||||
|
|
Loading…
Reference in a new issue