Skip to content

Commit 538c853

Browse files
authored
Merge pull request matrix-org#4838 from matrix-org/t3chguy/hf1
Fix Welcome.html CAS and SSO URLs not working
2 parents 85c5bb3 + 6116cfc commit 538c853

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

src/BasePlatform.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import {CheckUpdatesPayload} from "./dispatcher/payloads/CheckUpdatesPayload";
2525
import {Action} from "./dispatcher/actions";
2626
import {hideToast as hideUpdateToast} from "./toasts/UpdateToast";
2727

28-
export const HOMESERVER_URL_KEY = "mx_hs_url";
29-
export const ID_SERVER_URL_KEY = "mx_is_url";
28+
export const SSO_HOMESERVER_URL_KEY = "mx_sso_hs_url";
29+
export const SSO_ID_SERVER_URL_KEY = "mx_sso_is_url";
3030

3131
export enum UpdateCheckStatus {
3232
Checking = "CHECKING",
@@ -221,7 +221,7 @@ export default abstract class BasePlatform {
221221

222222
setLanguage(preferredLangs: string[]) {}
223223

224-
getSSOCallbackUrl(fragmentAfterLogin: string): URL {
224+
protected getSSOCallbackUrl(fragmentAfterLogin: string): URL {
225225
const url = new URL(window.location.href);
226226
url.hash = fragmentAfterLogin || "";
227227
return url;
@@ -235,9 +235,9 @@ export default abstract class BasePlatform {
235235
*/
236236
startSingleSignOn(mxClient: MatrixClient, loginType: "sso" | "cas", fragmentAfterLogin: string) {
237237
// persist hs url and is url for when the user is returned to the app with the login token
238-
localStorage.setItem(HOMESERVER_URL_KEY, mxClient.getHomeserverUrl());
238+
localStorage.setItem(SSO_HOMESERVER_URL_KEY, mxClient.getHomeserverUrl());
239239
if (mxClient.getIdentityServerUrl()) {
240-
localStorage.setItem(ID_SERVER_URL_KEY, mxClient.getIdentityServerUrl());
240+
localStorage.setItem(SSO_ID_SERVER_URL_KEY, mxClient.getIdentityServerUrl());
241241
}
242242
const callbackUrl = this.getSSOCallbackUrl(fragmentAfterLogin);
243243
window.location.href = mxClient.getSsoLoginUrl(callbackUrl.toString(), loginType); // redirect to SSO

src/Lifecycle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ import {IntegrationManagers} from "./integrations/IntegrationManagers";
4141
import {Mjolnir} from "./mjolnir/Mjolnir";
4242
import DeviceListener from "./DeviceListener";
4343
import {Jitsi} from "./widgets/Jitsi";
44-
import {HOMESERVER_URL_KEY, ID_SERVER_URL_KEY} from "./BasePlatform";
44+
import {SSO_HOMESERVER_URL_KEY, SSO_ID_SERVER_URL_KEY} from "./BasePlatform";
45+
46+
const HOMESERVER_URL_KEY = "mx_hs_url";
47+
const ID_SERVER_URL_KEY = "mx_is_url";
4548

4649
/**
4750
* Called at startup, to attempt to build a logged-in Matrix session. It tries
@@ -164,8 +167,8 @@ export function attemptTokenLogin(queryParams, defaultDeviceDisplayName) {
164167
return Promise.resolve(false);
165168
}
166169

167-
const homeserver = localStorage.getItem(HOMESERVER_URL_KEY);
168-
const identityServer = localStorage.getItem(ID_SERVER_URL_KEY);
170+
const homeserver = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
171+
const identityServer = localStorage.getItem(SSO_ID_SERVER_URL_KEY);
169172
if (!homeserver) {
170173
console.warn("Cannot log in with token: can't determine HS URL to use");
171174
return Promise.resolve(false);

src/components/structures/MatrixChat.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
*/
1919

2020
import React, { createRef } from 'react';
21+
import { createClient } from "matrix-js-sdk/src";
2122
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
2223
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
2324
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
@@ -1612,6 +1613,19 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
16121613
});
16131614
} else if (screen === 'directory') {
16141615
dis.fire(Action.ViewRoomDirectory);
1616+
} else if (screen === "start_sso" || screen === "start_cas") {
1617+
// TODO if logged in, skip SSO
1618+
let cli = MatrixClientPeg.get();
1619+
if (!cli) {
1620+
const {hsUrl, isUrl} = this.props.serverConfig;
1621+
cli = createClient({
1622+
baseUrl: hsUrl,
1623+
idBaseUrl: isUrl,
1624+
});
1625+
}
1626+
1627+
const type = screen === "start_sso" ? "sso" : "cas";
1628+
PlatformPeg.get().startSingleSignOn(cli, type, this.getFragmentAfterLogin());
16151629
} else if (screen === 'groups') {
16161630
dis.dispatch({
16171631
action: 'view_my_groups',
@@ -1915,17 +1929,19 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
19151929
this.onLoggedIn();
19161930
};
19171931

1918-
render() {
1919-
// console.log(`Rendering MatrixChat with view ${this.state.view}`);
1920-
1932+
getFragmentAfterLogin() {
19211933
let fragmentAfterLogin = "";
19221934
if (this.props.initialScreenAfterLogin &&
19231935
// XXX: workaround for https://github.com/vector-im/riot-web/issues/11643 causing a login-loop
19241936
!["welcome", "login", "register"].includes(this.props.initialScreenAfterLogin.screen)
19251937
) {
19261938
fragmentAfterLogin = `/${this.props.initialScreenAfterLogin.screen}`;
19271939
}
1940+
return fragmentAfterLogin;
1941+
}
19281942

1943+
render() {
1944+
const fragmentAfterLogin = this.getFragmentAfterLogin();
19291945
let view;
19301946

19311947
if (this.state.view === Views.LOADING) {
@@ -2004,7 +2020,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
20042020
}
20052021
} else if (this.state.view === Views.WELCOME) {
20062022
const Welcome = sdk.getComponent('auth.Welcome');
2007-
view = <Welcome {...this.getServerProperties()} fragmentAfterLogin={fragmentAfterLogin} />;
2023+
view = <Welcome />;
20082024
} else if (this.state.view === Views.REGISTER) {
20092025
const Registration = sdk.getComponent('structures.auth.Registration');
20102026
view = (

src/components/structures/auth/SoftLogout.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {MatrixClientPeg} from "../../../MatrixClientPeg";
2525
import {sendLoginRequest} from "../../../Login";
2626
import AuthPage from "../../views/auth/AuthPage";
2727
import SSOButton from "../../views/elements/SSOButton";
28-
import {HOMESERVER_URL_KEY, ID_SERVER_URL_KEY} from "../../../BasePlatform";
28+
import {SSO_HOMESERVER_URL_KEY, SSO_ID_SERVER_URL_KEY} from "../../../BasePlatform";
2929

3030
const LOGIN_VIEW = {
3131
LOADING: 1,
@@ -158,8 +158,8 @@ export default class SoftLogout extends React.Component {
158158
async trySsoLogin() {
159159
this.setState({busy: true});
160160

161-
const hsUrl = localStorage.getItem(HOMESERVER_URL_KEY);
162-
const isUrl = localStorage.getItem(ID_SERVER_URL_KEY) || MatrixClientPeg.get().getIdentityServerUrl();
161+
const hsUrl = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
162+
const isUrl = localStorage.getItem(SSO_ID_SERVER_URL_KEY) || MatrixClientPeg.get().getIdentityServerUrl();
163163
const loginType = "m.login.token";
164164
const loginParams = {
165165
token: this.props.realQueryParams['loginToken'],

src/components/views/auth/Welcome.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import React from 'react';
1818
import * as sdk from '../../../index';
1919
import SdkConfig from '../../../SdkConfig';
2020
import AuthPage from "./AuthPage";
21-
import * as Matrix from "matrix-js-sdk";
2221
import {_td} from "../../../languageHandler";
23-
import PlatformPeg from "../../../PlatformPeg";
2422

2523
// translatable strings for Welcome pages
2624
_td("Sign in with SSO");
@@ -39,24 +37,15 @@ export default class Welcome extends React.PureComponent {
3937
pageUrl = 'welcome.html';
4038
}
4139

42-
const {hsUrl, isUrl} = this.props.serverConfig;
43-
const tmpClient = Matrix.createClient({
44-
baseUrl: hsUrl,
45-
idBaseUrl: isUrl,
46-
});
47-
const plaf = PlatformPeg.get();
48-
const callbackUrl = plaf.getSSOCallbackUrl(tmpClient.getHomeserverUrl(), tmpClient.getIdentityServerUrl(),
49-
this.props.fragmentAfterLogin);
50-
5140
return (
5241
<AuthPage>
5342
<div className="mx_Welcome">
5443
<EmbeddedPage
5544
className="mx_WelcomePage"
5645
url={pageUrl}
5746
replaceMap={{
58-
"$riot:ssoUrl": tmpClient.getSsoLoginUrl(callbackUrl.toString(), "sso"),
59-
"$riot:casUrl": tmpClient.getSsoLoginUrl(callbackUrl.toString(), "cas"),
47+
"$riot:ssoUrl": "#/start_sso",
48+
"$riot:casUrl": "#/start_cas",
6049
}}
6150
/>
6251
<LanguageSelector />

0 commit comments

Comments
 (0)