Merge pull request #16415 from bekliev/fix/sso-redirect

fix / sso: make sure to delete only loginToken after redirect
This commit is contained in:
Michael Telatynski 2021-02-11 16:57:28 +00:00 committed by GitHub
commit 19a07bc4a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 29 deletions

View file

@ -66,8 +66,7 @@
"react": "^16.14.0", "react": "^16.14.0",
"react-dom": "^16.14.0", "react-dom": "^16.14.0",
"sanitize-html": "github:apostrophecms/sanitize-html#3c7f93f2058f696f5359e3e58d464161647226db", "sanitize-html": "github:apostrophecms/sanitize-html#3c7f93f2058f696f5359e3e58d464161647226db",
"ua-parser-js": "^0.7.23", "ua-parser-js": "^0.7.23"
"url": "^0.11.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.12.10", "@babel/core": "^7.12.10",

View file

@ -23,7 +23,6 @@ import React from 'react';
// this incidentally means we can forget our React imports in JSX files without penalty. // this incidentally means we can forget our React imports in JSX files without penalty.
window.React = React; window.React = React;
import url from 'url';
import * as sdk from 'matrix-react-sdk'; import * as sdk from 'matrix-react-sdk';
import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg'; import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg';
import {_td, newTranslatableError} from 'matrix-react-sdk/src/languageHandler'; import {_td, newTranslatableError} from 'matrix-react-sdk/src/languageHandler';
@ -120,11 +119,12 @@ function onTokenLoginCompleted() {
// if we did a token login, we're now left with the token, hs and is // if we did a token login, we're now left with the token, hs and is
// url as query params in the url; a little nasty but let's redirect to // url as query params in the url; a little nasty but let's redirect to
// clear them. // clear them.
const parsedUrl = url.parse(window.location.href); const url = new URL(window.location.href);
parsedUrl.search = "";
const formatted = url.format(parsedUrl); url.searchParams.delete("loginToken");
console.log(`Redirecting to ${formatted} to drop loginToken from queryparams`);
window.history.replaceState(null, "", formatted); console.log(`Redirecting to ${url.href} to drop loginToken from queryparams`);
window.history.replaceState(null, "", url.href);
} }
export async function loadApp(fragParams: {}) { export async function loadApp(fragParams: {}) {

View file

@ -26,7 +26,6 @@ import {hideToast as hideUpdateToast, showToast as showUpdateToast} from "matrix
import {Action} from "matrix-react-sdk/src/dispatcher/actions"; import {Action} from "matrix-react-sdk/src/dispatcher/actions";
import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload'; import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload';
import url from 'url';
import UAParser from 'ua-parser-js'; import UAParser from 'ua-parser-js';
const POKE_RATE_MS = 10 * 60 * 1000; // 10 min const POKE_RATE_MS = 10 * 60 * 1000; // 10 min
@ -184,17 +183,13 @@ export default class WebPlatform extends VectorBasePlatform {
getDefaultDeviceDisplayName(): string { getDefaultDeviceDisplayName(): string {
// strip query-string and fragment from uri // strip query-string and fragment from uri
const u = url.parse(window.location.href); const url = new URL(window.location.href);
u.protocol = "";
u.search = "";
u.hash = "";
// Remove trailing slash if present
u.pathname = u.pathname.replace(/\/$/, "");
let appName = u.format(); // `appName` in the format `develop.element.io/abc/xyz`
// Remove leading slashes if present const appName = [
appName = appName.replace(/^\/\//, ""); url.host,
// `appName` is now in the format `develop.element.io`. url.pathname.replace(/\/$/, ""), // Remove trailing slash if present
].join("");
const ua = new UAParser(); const ua = new UAParser();
const browserName = ua.getBrowser().name || "unknown browser"; const browserName = ua.getBrowser().name || "unknown browser";

View file

@ -8890,16 +8890,7 @@ postcss-attribute-case-insensitive@^4.0.1:
postcss "^7.0.2" postcss "^7.0.2"
postcss-selector-parser "^6.0.2" postcss-selector-parser "^6.0.2"
postcss-calc@^7.0.1: postcss-calc@^7.0.1, postcss-calc@^7.0.5:
version "7.0.5"
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-7.0.5.tgz#f8a6e99f12e619c2ebc23cf6c486fdc15860933e"
integrity sha512-1tKHutbGtLtEZF6PT4JSihCHfIVldU72mZ8SdZHIYriIZ9fh9k9aWSppaT8rHsyI3dX+KSR+W+Ix9BMY3AODrg==
dependencies:
postcss "^7.0.27"
postcss-selector-parser "^6.0.2"
postcss-value-parser "^4.0.2"
postcss-calc@^7.0.5:
version "7.0.5" version "7.0.5"
resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-7.0.5.tgz#f8a6e99f12e619c2ebc23cf6c486fdc15860933e" resolved "https://registry.yarnpkg.com/postcss-calc/-/postcss-calc-7.0.5.tgz#f8a6e99f12e619c2ebc23cf6c486fdc15860933e"
integrity sha512-1tKHutbGtLtEZF6PT4JSihCHfIVldU72mZ8SdZHIYriIZ9fh9k9aWSppaT8rHsyI3dX+KSR+W+Ix9BMY3AODrg== integrity sha512-1tKHutbGtLtEZF6PT4JSihCHfIVldU72mZ8SdZHIYriIZ9fh9k9aWSppaT8rHsyI3dX+KSR+W+Ix9BMY3AODrg==