From e98b753c217eb727f844ae080d1c67103b13859f Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 23 Sep 2019 12:21:25 +0100 Subject: [PATCH] Use alternate MSISDN submit URL when returned by HS This changes MSISDN token submission to send to an arbitrary URL (instead of the current IS) when the HS provides such a URL. Fixes https://github.com/vector-im/riot-web/issues/10923 --- src/AddThreepid.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/AddThreepid.js b/src/AddThreepid.js index 3b66b1d7ee..84fa07ff4b 100644 --- a/src/AddThreepid.js +++ b/src/AddThreepid.js @@ -35,6 +35,8 @@ import IdentityAuthClient from './IdentityAuthClient'; export default class AddThreepid { constructor() { this.clientSecret = MatrixClientPeg.get().generateClientSecret(); + this.sessionId = null; + this.submitUrl = null; } /** @@ -101,6 +103,7 @@ export default class AddThreepid { phoneCountry, phoneNumber, this.clientSecret, 1, ).then((res) => { this.sessionId = res.sid; + this.submitUrl = res.submit_url; return res; }, function(err) { if (err.errcode === 'M_THREEPID_IN_USE') { @@ -198,12 +201,23 @@ export default class AddThreepid { async haveMsisdnToken(msisdnToken) { const authClient = new IdentityAuthClient(); const identityAccessToken = await authClient.getAccessToken(); - const result = await MatrixClientPeg.get().submitMsisdnToken( - this.sessionId, - this.clientSecret, - msisdnToken, - identityAccessToken, - ); + + let result; + if (this.submitUrl) { + result = await MatrixClientPeg.get().submitMsisdnTokenOtherUrl( + this.submitUrl, + this.sessionId, + this.clientSecret, + msisdnToken, + ); + } else { + result = await MatrixClientPeg.get().submitMsisdnToken( + this.sessionId, + this.clientSecret, + msisdnToken, + identityAccessToken, + ); + } if (result.errcode) { throw result; }