From e9528ebb98107b572ea5a07907690c407757d889 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 9 Jul 2019 18:50:01 +0100 Subject: [PATCH 01/14] Support for MSC2140 (terms of service for IS/IM) --- src/base-apis.js | 31 +++++++++++++++++++++++++++++++ src/http-api.js | 6 ++++++ src/matrix.js | 2 ++ src/servicetypes.js | 20 ++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 src/servicetypes.js diff --git a/src/base-apis.js b/src/base-apis.js index 59d73dc8718..9f9a8cd14ca 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 Vector Creations Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,6 +17,8 @@ limitations under the License. */ "use strict"; +import { SERVICETYPES } from './servicetypes'; + /** * This is an internal module. MatrixBaseApis is currently only meant to be used * by {@link client~MatrixClient}. @@ -26,6 +29,17 @@ limitations under the License. const httpApi = require("./http-api"); const utils = require("./utils"); +function termsUrlForService(serviceType, baseUrl) { + switch (serviceType) { + case SERVICETYPES.IS: + return baseUrl + httpApi.PREFIX_IDENTITY_V2 + case SERVICETYPES.IM: + return baseUrl + '/terms/' + default: + throw new Error('Unsupported service type'); + } +} + /** * Low-level wrappers for the Matrix APIs * @@ -1888,6 +1902,23 @@ MatrixBaseApis.prototype.getThirdpartyUser = function(protocol, params) { ); }; +MatrixBaseApis.prototype.getTerms = function(serviceType, baseUrl, accessToken) { + const url = termsUrlForService(serviceType, baseUrl); + return this._http.requestOtherUrl( + undefined, 'GET', url, null, null, null, + ); +}; + +MatrixBaseApis.prototype.agreeToTerms = function(serviceType, baseUrl, accessToken, termsUrls) { + const url = termsUrlForService(serviceType, baseUrl); + const headers = { + Authorization: "Bearer " + accessToken, + }; + return this._http.requestOtherUrl( + undefined, 'POST', url, null, {user_accepts: termsUrls}, { headers }, + ); +}; + /** * MatrixBaseApis object */ diff --git a/src/http-api.js b/src/http-api.js index 16171151afc..c90847d8b52 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -1,5 +1,6 @@ /* Copyright 2015, 2016 OpenMarket Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -50,6 +51,11 @@ module.exports.PREFIX_UNSTABLE = "/_matrix/client/unstable"; */ module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1"; +/** + * URI path for the v2 identity API + */ +module.exports.PREFIX_IDENTITY_V2 = "/_matrix/identity/v2"; + /** * URI path for the media repo API */ diff --git a/src/matrix.js b/src/matrix.js index 0460927ff06..b1f224a1821 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 Vector Creations Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -76,6 +77,7 @@ module.exports.InteractiveAuth = require("./interactive-auth"); /** The {@link module:auto-discovery|AutoDiscovery} class. */ module.exports.AutoDiscovery = require("./autodiscovery").AutoDiscovery; +module.exports.SERVICETYPES = require('./servicetypes').SERVICETYPES; module.exports.MemoryCryptoStore = require("./crypto/store/memory-crypto-store").default; diff --git a/src/servicetypes.js b/src/servicetypes.js new file mode 100644 index 00000000000..1f76155bbc9 --- /dev/null +++ b/src/servicetypes.js @@ -0,0 +1,20 @@ +/* +Copyright 2019 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +export const SERVICETYPES = Object.freeze({ + IS: 'SERVICETYPE_IS', + IM: 'SERVICETYPE_IM', +}); From 524fea1297633f627a9bce1d29adad38a19b302e Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 10 Jul 2019 10:43:54 +0100 Subject: [PATCH 02/14] lint --- src/base-apis.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/base-apis.js b/src/base-apis.js index 9f9a8cd14ca..d979ff27841 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -32,9 +32,9 @@ const utils = require("./utils"); function termsUrlForService(serviceType, baseUrl) { switch (serviceType) { case SERVICETYPES.IS: - return baseUrl + httpApi.PREFIX_IDENTITY_V2 + return baseUrl + httpApi.PREFIX_IDENTITY_V2; case SERVICETYPES.IM: - return baseUrl + '/terms/' + return baseUrl + '/terms/'; default: throw new Error('Unsupported service type'); } @@ -1909,7 +1909,9 @@ MatrixBaseApis.prototype.getTerms = function(serviceType, baseUrl, accessToken) ); }; -MatrixBaseApis.prototype.agreeToTerms = function(serviceType, baseUrl, accessToken, termsUrls) { +MatrixBaseApis.prototype.agreeToTerms = function( + serviceType, baseUrl, accessToken, termsUrls, +) { const url = termsUrlForService(serviceType, baseUrl); const headers = { Authorization: "Bearer " + accessToken, From bb486f5148adc0ea700d4c2e91ee2751fb06add4 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 10 Jul 2019 11:47:36 +0100 Subject: [PATCH 03/14] SERVICE_TYPES Co-Authored-By: J. Ryan Stinnett --- src/matrix.js | 2 +- src/servicetypes.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/matrix.js b/src/matrix.js index b1f224a1821..244b10f2477 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -77,7 +77,7 @@ module.exports.InteractiveAuth = require("./interactive-auth"); /** The {@link module:auto-discovery|AutoDiscovery} class. */ module.exports.AutoDiscovery = require("./autodiscovery").AutoDiscovery; -module.exports.SERVICETYPES = require('./servicetypes').SERVICETYPES; +module.exports.SERVICE_TYPES = require('./service-types').SERVICE_TYPES; module.exports.MemoryCryptoStore = require("./crypto/store/memory-crypto-store").default; diff --git a/src/servicetypes.js b/src/servicetypes.js index 1f76155bbc9..5cb0a5d36c3 100644 --- a/src/servicetypes.js +++ b/src/servicetypes.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -export const SERVICETYPES = Object.freeze({ - IS: 'SERVICETYPE_IS', - IM: 'SERVICETYPE_IM', +export const SERVICE_TYPES = Object.freeze({ + IS: 'SERVICE_TYPE_IS', + IM: 'SERVICE_TYPE_IM', }); From 4c713e338728b08c970ebe1249cacc87f462a8c4 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 10 Jul 2019 11:53:59 +0100 Subject: [PATCH 04/14] s/servicetypes/service-types/ --- src/{servicetypes.js => service-types.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{servicetypes.js => service-types.js} (100%) diff --git a/src/servicetypes.js b/src/service-types.js similarity index 100% rename from src/servicetypes.js rename to src/service-types.js From 39d4bf149410da4d7a0c3b48726fb527789adf1f Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 10 Jul 2019 12:08:13 +0100 Subject: [PATCH 05/14] SERVICE_TYPES --- src/base-apis.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/base-apis.js b/src/base-apis.js index d979ff27841..c50d14d86b3 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -17,7 +17,7 @@ limitations under the License. */ "use strict"; -import { SERVICETYPES } from './servicetypes'; +import { SERVICE_TYPES } from './service-types'; /** * This is an internal module. MatrixBaseApis is currently only meant to be used @@ -31,9 +31,9 @@ const utils = require("./utils"); function termsUrlForService(serviceType, baseUrl) { switch (serviceType) { - case SERVICETYPES.IS: + case SERVICE_TYPES.IS: return baseUrl + httpApi.PREFIX_IDENTITY_V2; - case SERVICETYPES.IM: + case SERVICE_TYPES.IM: return baseUrl + '/terms/'; default: throw new Error('Unsupported service type'); From 52c139dcdcf906e868a20568508f4f2113ecfe61 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 10 Jul 2019 12:15:31 +0100 Subject: [PATCH 06/14] Forgot /terms for ISes and IMs shouldn't have a slash --- src/base-apis.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base-apis.js b/src/base-apis.js index c50d14d86b3..7205208c913 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -32,9 +32,9 @@ const utils = require("./utils"); function termsUrlForService(serviceType, baseUrl) { switch (serviceType) { case SERVICE_TYPES.IS: - return baseUrl + httpApi.PREFIX_IDENTITY_V2; + return baseUrl + httpApi.PREFIX_IDENTITY_V2 + '/terms'; case SERVICE_TYPES.IM: - return baseUrl + '/terms/'; + return baseUrl + '/terms'; default: throw new Error('Unsupported service type'); } From b8957fa9175af0f8760366a3c261cb47bd9393fd Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 10 Jul 2019 12:17:52 +0100 Subject: [PATCH 07/14] omit null params --- src/base-apis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base-apis.js b/src/base-apis.js index 7205208c913..5e3578eb212 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -1905,7 +1905,7 @@ MatrixBaseApis.prototype.getThirdpartyUser = function(protocol, params) { MatrixBaseApis.prototype.getTerms = function(serviceType, baseUrl, accessToken) { const url = termsUrlForService(serviceType, baseUrl); return this._http.requestOtherUrl( - undefined, 'GET', url, null, null, null, + undefined, 'GET', url, ); }; From 9e5c2732c9a44b81b03c47b63ffb10d5d77a8f74 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 10 Jul 2019 12:18:41 +0100 Subject: [PATCH 08/14] consistent spacing --- src/base-apis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base-apis.js b/src/base-apis.js index 5e3578eb212..c46d6be16d6 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -1917,7 +1917,7 @@ MatrixBaseApis.prototype.agreeToTerms = function( Authorization: "Bearer " + accessToken, }; return this._http.requestOtherUrl( - undefined, 'POST', url, null, {user_accepts: termsUrls}, { headers }, + undefined, 'POST', url, null, { user_accepts: termsUrls }, { headers }, ); }; From c3b5767999d25a10cded15dd03ecfde4b01f37c5 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 10 Jul 2019 12:19:12 +0100 Subject: [PATCH 09/14] update comment to reflect right version --- src/http-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http-api.js b/src/http-api.js index c90847d8b52..f0d9ed016bc 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -47,7 +47,7 @@ module.exports.PREFIX_R0 = "/_matrix/client/r0"; module.exports.PREFIX_UNSTABLE = "/_matrix/client/unstable"; /** - * URI path for the identity API + * URI path for v1 of the the identity API */ module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1"; From 5b9e158035b7ca6755d8f8179dfe855cbfb9f67e Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 11 Jul 2019 16:28:41 +0100 Subject: [PATCH 10/14] unused param getTerms is un-authed so doesn't need the access token --- src/base-apis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base-apis.js b/src/base-apis.js index c46d6be16d6..c8fa15d5522 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -1902,7 +1902,7 @@ MatrixBaseApis.prototype.getThirdpartyUser = function(protocol, params) { ); }; -MatrixBaseApis.prototype.getTerms = function(serviceType, baseUrl, accessToken) { +MatrixBaseApis.prototype.getTerms = function(serviceType, baseUrl) { const url = termsUrlForService(serviceType, baseUrl); return this._http.requestOtherUrl( undefined, 'GET', url, From c74e0bb6b3771a8b9e6d6d8b7884881aa6da1f0e Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 11 Jul 2019 16:29:27 +0100 Subject: [PATCH 11/14] tell people what an IS/IM are --- src/service-types.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service-types.js b/src/service-types.js index 5cb0a5d36c3..0803b9247f8 100644 --- a/src/service-types.js +++ b/src/service-types.js @@ -15,6 +15,6 @@ limitations under the License. */ export const SERVICE_TYPES = Object.freeze({ - IS: 'SERVICE_TYPE_IS', - IM: 'SERVICE_TYPE_IM', + IS: 'SERVICE_TYPE_IS', // An Identity Service + IM: 'SERVICE_TYPE_IM', // An Integration Manager }); From 8004e82c50a8b090d099850b1b12381744da114d Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 15 Jul 2019 13:51:39 +0100 Subject: [PATCH 12/14] Use _matrix prefix for terms API --- src/base-apis.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base-apis.js b/src/base-apis.js index c8fa15d5522..0fe2a646215 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -32,9 +32,9 @@ const utils = require("./utils"); function termsUrlForService(serviceType, baseUrl) { switch (serviceType) { case SERVICE_TYPES.IS: - return baseUrl + httpApi.PREFIX_IDENTITY_V2 + '/terms'; + return baseUrl + httpApi.PREFIX_IDENTITY_V2 + '_matrix/v2/integrations/v1/terms'; case SERVICE_TYPES.IM: - return baseUrl + '/terms'; + return baseUrl + '/_matrix/integrations/v1/terms'; default: throw new Error('Unsupported service type'); } From b694d53b7300121d2603e834142a83cc3597e8f8 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 15 Jul 2019 14:26:16 +0100 Subject: [PATCH 13/14] Revert 8004e82c50a8b090d099850b1b12381744da114d We need to switch the paths over all at once, so we can't commit this yet: leave it until scalar suypports the new API then we can update develop to use the _matrix paths. (Also for some reason I broke the IS path too) --- src/base-apis.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base-apis.js b/src/base-apis.js index 0fe2a646215..c8fa15d5522 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -32,9 +32,9 @@ const utils = require("./utils"); function termsUrlForService(serviceType, baseUrl) { switch (serviceType) { case SERVICE_TYPES.IS: - return baseUrl + httpApi.PREFIX_IDENTITY_V2 + '_matrix/v2/integrations/v1/terms'; + return baseUrl + httpApi.PREFIX_IDENTITY_V2 + '/terms'; case SERVICE_TYPES.IM: - return baseUrl + '/_matrix/integrations/v1/terms'; + return baseUrl + '/terms'; default: throw new Error('Unsupported service type'); } From fafd6df13e3817397860f8afc386646c5859ad5c Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 22 Jul 2019 18:53:36 +0100 Subject: [PATCH 14/14] Use standard _matrix path for terms endpoints --- src/base-apis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base-apis.js b/src/base-apis.js index c8fa15d5522..49380ceef2d 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -34,7 +34,7 @@ function termsUrlForService(serviceType, baseUrl) { case SERVICE_TYPES.IS: return baseUrl + httpApi.PREFIX_IDENTITY_V2 + '/terms'; case SERVICE_TYPES.IM: - return baseUrl + '/terms'; + return baseUrl + '/_matrix/integrations/v1/terms'; default: throw new Error('Unsupported service type'); }