From 348f6f971a06d41719daa748e7bc1c42dbb9773f Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 1 Aug 2019 12:46:59 +0100 Subject: [PATCH 1/3] Show terms modal when inviting by email This invokes the terms modal flow when inviting someone by email. Entering an email triggers a lookup to the IS, and if it has terms you need to agree to, then a separate modal is shown to complete this activity. You then come back to invite screen after agreeing to the terms. Fixes https://github.com/vector-im/riot-web/issues/10093 --- src/IdentityAuthClient.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/IdentityAuthClient.js b/src/IdentityAuthClient.js index 58a1773924..245b8a8c3c 100644 --- a/src/IdentityAuthClient.js +++ b/src/IdentityAuthClient.js @@ -14,7 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ +import * as Matrix from 'matrix-js-sdk'; + import MatrixClientPeg from './MatrixClientPeg'; +import { Service, startTermsFlow } from './Terms'; export default class IdentityAuthClient { constructor() { @@ -57,7 +60,20 @@ export default class IdentityAuthClient { } async _checkToken(token) { - await MatrixClientPeg.get().getIdentityAccount(token); + try { + await MatrixClientPeg.get().getIdentityAccount(token); + } catch (e) { + if (e.errcode === "M_TERMS_NOT_SIGNED") { + console.log("Identity Server requires new terms to be agreed to"); + await startTermsFlow([new Service( + Matrix.SERVICE_TYPES.IS, + MatrixClientPeg.get().idBaseUrl, + token, + )]); + return; + } + throw e; + } // We should ensure the token in `localStorage` is cleared // appropriately. We already clear storage on sign out, but we'll need From a85efe5f65af544a88950a093f5e4dfc801097ea Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 2 Aug 2019 14:43:36 +0100 Subject: [PATCH 2/3] Tweak import --- src/IdentityAuthClient.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IdentityAuthClient.js b/src/IdentityAuthClient.js index 245b8a8c3c..7b36a4f4a0 100644 --- a/src/IdentityAuthClient.js +++ b/src/IdentityAuthClient.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import * as Matrix from 'matrix-js-sdk'; +import { SERVICE_TYPES } from 'matrix-js-sdk'; import MatrixClientPeg from './MatrixClientPeg'; import { Service, startTermsFlow } from './Terms'; @@ -66,7 +66,7 @@ export default class IdentityAuthClient { if (e.errcode === "M_TERMS_NOT_SIGNED") { console.log("Identity Server requires new terms to be agreed to"); await startTermsFlow([new Service( - Matrix.SERVICE_TYPES.IS, + SERVICE_TYPES.IS, MatrixClientPeg.get().idBaseUrl, token, )]); From 7ccc218a98c9942c220bab5ca37df4fee4af9cb4 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 2 Aug 2019 15:21:53 +0100 Subject: [PATCH 3/3] Tweak control flow to avoid duplicate terms prompts --- src/IdentityAuthClient.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/IdentityAuthClient.js b/src/IdentityAuthClient.js index 7b36a4f4a0..755205d5e2 100644 --- a/src/IdentityAuthClient.js +++ b/src/IdentityAuthClient.js @@ -17,7 +17,7 @@ limitations under the License. import { SERVICE_TYPES } from 'matrix-js-sdk'; import MatrixClientPeg from './MatrixClientPeg'; -import { Service, startTermsFlow } from './Terms'; +import { Service, startTermsFlow, TermsNotSignedError } from './Terms'; export default class IdentityAuthClient { constructor() { @@ -43,17 +43,26 @@ export default class IdentityAuthClient { if (!token) { token = await this.registerForToken(); - this.accessToken = token; - window.localStorage.setItem("mx_is_access_token", token); + if (token) { + this.accessToken = token; + window.localStorage.setItem("mx_is_access_token", token); + } + return token; } try { await this._checkToken(token); } catch (e) { + if (e instanceof TermsNotSignedError) { + // Retrying won't help this + throw e; + } // Retry in case token expired token = await this.registerForToken(); - this.accessToken = token; - window.localStorage.setItem("mx_is_access_token", token); + if (token) { + this.accessToken = token; + window.localStorage.setItem("mx_is_access_token", token); + } } return token; @@ -89,8 +98,8 @@ export default class IdentityAuthClient { await MatrixClientPeg.get().registerWithIdentityServer(hsOpenIdToken); await this._checkToken(identityAccessToken); return identityAccessToken; - } catch (err) { - if (err.cors === "rejected" || err.httpStatus === 404) { + } catch (e) { + if (e.cors === "rejected" || e.httpStatus === 404) { // Assume IS only supports deprecated v1 API for now // TODO: Remove this path once v2 is only supported version // See https://github.com/vector-im/riot-web/issues/10443 @@ -98,7 +107,7 @@ export default class IdentityAuthClient { this.authEnabled = false; return; } - console.error(err); + throw e; } } }