From 909b29368b15e3a4240524b3887edb1d53b5be1d Mon Sep 17 00:00:00 2001 From: turt2live Date: Sat, 26 Aug 2017 13:41:48 -0600 Subject: [PATCH 1/2] Redirect starter links to the desired integration manager When not using Scalar for the integrations manager, the scalar_token in Riot may not be valid for scalar.vector.im, leading to authentication problems. Starter links should instead point to the desired integrations manager where the token is more likely to be valid. Signed-off-by: Travis Ralston --- src/ScalarAuthClient.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index 0b753cf3ab1..350f2da4806 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -90,6 +90,11 @@ class ScalarAuthClient { } getStarterLink(starterLinkUrl) { + // If the starter link points to Scalar, but the integrations manager isn't scalar, redirect accordingly. + // The integration manager is responsible for maintaining the starter link route. + let scalarUrl = SdkConfig.get().integrations_rest_url; + if (!starterLinkUrl.startsWith(scalarUrl) && starterLinkUrl.startsWith("https://scalar.vector.im/api")) + starterLinkUrl = scalarUrl + starterLinkUrl.substring("https://scalar.vector.im/api".length); return starterLinkUrl + "?scalar_token=" + encodeURIComponent(this.scalarToken); } } From fd41a32d74d277d8cd8637f37d43751339f8dff9 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 16 Dec 2017 20:42:41 -0700 Subject: [PATCH 2/2] Make use of the integrations manager by default Unless an explicit URL is given, then we'll just use that. Signed-off-by: Travis Ralston --- src/ScalarAuthClient.js | 20 +++++++++++++++----- src/components/views/messages/TextualBody.js | 5 +++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index d00a5a8db71..866b9007324 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -118,12 +118,22 @@ class ScalarAuthClient { return url; } + getScalarInterfaceUrlForPath(path) { + if (path.startsWith("http://") || path.startsWith("https://")) { + // It's already an interface URL, so we'll just give it a token and move on + return this.getStarterLink(path); + } + + let url = SdkConfig.get().integrations_ui_url; + + // Take off the slashes as we'll be manually adding them later on + if (url.endsWith("/")) url = url.substring(0, url.length - 1); + if (path.startsWith("/")) path = path.substring(1); + + return this.getStarterLink(url + "/" + path); + } + getStarterLink(starterLinkUrl) { - // If the starter link points to Scalar, but the integrations manager isn't scalar, redirect accordingly. - // The integration manager is responsible for maintaining the starter link route. - let scalarUrl = SdkConfig.get().integrations_rest_url; - if (!starterLinkUrl.startsWith(scalarUrl) && starterLinkUrl.startsWith("https://scalar.vector.im/api")) - starterLinkUrl = scalarUrl + starterLinkUrl.substring("https://scalar.vector.im/api".length); return starterLinkUrl + "?scalar_token=" + encodeURIComponent(this.scalarToken); } } diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 4b096d0a767..2e913168fad 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -35,6 +35,7 @@ import {RoomMember} from 'matrix-js-sdk'; import classNames from 'classnames'; import SettingsStore from "../../../settings/SettingsStore"; import PushProcessor from 'matrix-js-sdk/lib/pushprocessor'; +import * as url from "url"; linkifyMatrix(linkify); @@ -387,9 +388,9 @@ module.exports = React.createClass({ // Go fetch a scalar token const scalarClient = new ScalarAuthClient(); scalarClient.connect().then(() => { - const completeUrl = scalarClient.getStarterLink(starterLink); + const completeUrl = scalarClient.getScalarInterfaceUrlForPath(starterLink); const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); - const integrationsUrl = SdkConfig.get().integrations_ui_url; + const integrationsUrl = url.parse(completeUrl).host; Modal.createTrackedDialog('Add an integration', '', QuestionDialog, { title: _t("Add an Integration"), description: