Skip to content

Commit 19a07bc

Browse files
authored
Merge pull request #16415 from bekliev/fix/sso-redirect
fix / sso: make sure to delete only loginToken after redirect
2 parents af2da9d + 438eef0 commit 19a07bc

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666
"react": "^16.14.0",
6767
"react-dom": "^16.14.0",
6868
"sanitize-html": "github:apostrophecms/sanitize-html#3c7f93f2058f696f5359e3e58d464161647226db",
69-
"ua-parser-js": "^0.7.23",
70-
"url": "^0.11.0"
69+
"ua-parser-js": "^0.7.23"
7170
},
7271
"devDependencies": {
7372
"@babel/core": "^7.12.10",

src/vector/app.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import React from 'react';
2323
// this incidentally means we can forget our React imports in JSX files without penalty.
2424
window.React = React;
2525

26-
import url from 'url';
2726
import * as sdk from 'matrix-react-sdk';
2827
import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg';
2928
import {_td, newTranslatableError} from 'matrix-react-sdk/src/languageHandler';
@@ -120,11 +119,12 @@ function onTokenLoginCompleted() {
120119
// if we did a token login, we're now left with the token, hs and is
121120
// url as query params in the url; a little nasty but let's redirect to
122121
// clear them.
123-
const parsedUrl = url.parse(window.location.href);
124-
parsedUrl.search = "";
125-
const formatted = url.format(parsedUrl);
126-
console.log(`Redirecting to ${formatted} to drop loginToken from queryparams`);
127-
window.history.replaceState(null, "", formatted);
122+
const url = new URL(window.location.href);
123+
124+
url.searchParams.delete("loginToken");
125+
126+
console.log(`Redirecting to ${url.href} to drop loginToken from queryparams`);
127+
window.history.replaceState(null, "", url.href);
128128
}
129129

130130
export async function loadApp(fragParams: {}) {

src/vector/platform/WebPlatform.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {hideToast as hideUpdateToast, showToast as showUpdateToast} from "matrix
2626
import {Action} from "matrix-react-sdk/src/dispatcher/actions";
2727
import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload';
2828

29-
import url from 'url';
3029
import UAParser from 'ua-parser-js';
3130

3231
const POKE_RATE_MS = 10 * 60 * 1000; // 10 min
@@ -184,17 +183,13 @@ export default class WebPlatform extends VectorBasePlatform {
184183

185184
getDefaultDeviceDisplayName(): string {
186185
// strip query-string and fragment from uri
187-
const u = url.parse(window.location.href);
188-
u.protocol = "";
189-
u.search = "";
190-
u.hash = "";
191-
// Remove trailing slash if present
192-
u.pathname = u.pathname.replace(/\/$/, "");
193-
194-
let appName = u.format();
195-
// Remove leading slashes if present
196-
appName = appName.replace(/^\/\//, "");
197-
// `appName` is now in the format `develop.element.io`.
186+
const url = new URL(window.location.href);
187+
188+
// `appName` in the format `develop.element.io/abc/xyz`
189+
const appName = [
190+
url.host,
191+
url.pathname.replace(/\/$/, ""), // Remove trailing slash if present
192+
].join("");
198193

199194
const ua = new UAParser();
200195
const browserName = ua.getBrowser().name || "unknown browser";

yarn.lock

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8890,16 +8890,7 @@ postcss-attribute-case-insensitive@^4.0.1:
88908890
postcss "^7.0.2"
88918891
postcss-selector-parser "^6.0.2"
88928892

8893-
postcss-calc@^7.0.1:
8894-
version "7.0.5"
8895-
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-7.0.5.tgz#f8a6e99f12e619c2ebc23cf6c486fdc15860933e"
8896-
integrity sha512-1tKHutbGtLtEZF6PT4JSihCHfIVldU72mZ8SdZHIYriIZ9fh9k9aWSppaT8rHsyI3dX+KSR+W+Ix9BMY3AODrg==
8897-
dependencies:
8898-
postcss "^7.0.27"
8899-
postcss-selector-parser "^6.0.2"
8900-
postcss-value-parser "^4.0.2"
8901-
8902-
postcss-calc@^7.0.5:
8893+
postcss-calc@^7.0.1, postcss-calc@^7.0.5:
89038894
version "7.0.5"
89048895
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-7.0.5.tgz#f8a6e99f12e619c2ebc23cf6c486fdc15860933e"
89058896
integrity sha512-1tKHutbGtLtEZF6PT4JSihCHfIVldU72mZ8SdZHIYriIZ9fh9k9aWSppaT8rHsyI3dX+KSR+W+Ix9BMY3AODrg==

0 commit comments

Comments
 (0)