Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit aa6ce97

Browse files
authored
Merge pull request #3534 from matrix-org/dbkr/add_threepid_ui_auth
Support UI Auth on adding email addresses & phone numbers
2 parents 4635b13 + 93aebf9 commit aa6ce97

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

src/AddThreepid.js

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
*/
1818

1919
import MatrixClientPeg from './MatrixClientPeg';
20+
import sdk from './index';
21+
import Modal from './Modal';
2022
import { _t } from './languageHandler';
2123
import IdentityAuthClient from './IdentityAuthClient';
2224

@@ -171,10 +173,29 @@ export default class AddThreepid {
171173
id_access_token: identityAccessToken,
172174
});
173175
} else {
174-
await MatrixClientPeg.get().addThreePidOnly({
175-
sid: this.sessionId,
176-
client_secret: this.clientSecret,
177-
});
176+
try {
177+
await this._makeAddThreepidOnlyRequest();
178+
179+
// The spec has always required this to use UI auth but synapse briefly
180+
// implemented it without, so this may just succeed and that's OK.
181+
return;
182+
} catch (e) {
183+
if (e.httpStatus !== 401 || !e.data || !e.data.flows) {
184+
// doesn't look like an interactive-auth failure
185+
throw e;
186+
}
187+
188+
// pop up an interactive auth dialog
189+
const InteractiveAuthDialog = sdk.getComponent("dialogs.InteractiveAuthDialog");
190+
191+
const { finished } = Modal.createTrackedDialog('Add Email', '', InteractiveAuthDialog, {
192+
title: _t("Add Email Address"),
193+
matrixClient: MatrixClientPeg.get(),
194+
authData: e.data,
195+
makeRequest: this._makeAddThreepidOnlyRequest,
196+
});
197+
return finished;
198+
}
178199
}
179200
} else {
180201
await MatrixClientPeg.get().addThreePid({
@@ -193,6 +214,18 @@ export default class AddThreepid {
193214
}
194215
}
195216

217+
/**
218+
* @param {Object} auth UI auth object
219+
* @return {Promise<Object>} Response from /3pid/add call (in current spec, an empty object)
220+
*/
221+
_makeAddThreepidOnlyRequest = (auth) => {
222+
return MatrixClientPeg.get().addThreePidOnly({
223+
sid: this.sessionId,
224+
client_secret: this.clientSecret,
225+
auth,
226+
});
227+
}
228+
196229
/**
197230
* Takes a phone number verification code as entered by the user and validates
198231
* it with the ID server, then if successful, adds the phone number.
@@ -233,10 +266,29 @@ export default class AddThreepid {
233266
id_access_token: await authClient.getAccessToken(),
234267
});
235268
} else {
236-
await MatrixClientPeg.get().addThreePidOnly({
237-
sid: this.sessionId,
238-
client_secret: this.clientSecret,
239-
});
269+
try {
270+
await this._makeAddThreepidOnlyRequest();
271+
272+
// The spec has always required this to use UI auth but synapse briefly
273+
// implemented it without, so this may just succeed and that's OK.
274+
return;
275+
} catch (e) {
276+
if (e.httpStatus !== 401 || !e.data || !e.data.flows) {
277+
// doesn't look like an interactive-auth failure
278+
throw e;
279+
}
280+
281+
// pop up an interactive auth dialog
282+
const InteractiveAuthDialog = sdk.getComponent("dialogs.InteractiveAuthDialog");
283+
284+
const { finished } = Modal.createTrackedDialog('Add MSISDN', '', InteractiveAuthDialog, {
285+
title: _t("Add Phone Number"),
286+
matrixClient: MatrixClientPeg.get(),
287+
authData: e.data,
288+
makeRequest: this._makeAddThreepidOnlyRequest,
289+
});
290+
return finished;
291+
}
240292
}
241293
} else {
242294
await MatrixClientPeg.get().addThreePid({

src/components/views/settings/account/EmailAddresses.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export default class EmailAddresses extends React.Component {
201201
"and then click continue again."),
202202
});
203203
} else {
204-
console.error("Unable to verify email address: " + err);
204+
console.error("Unable to verify email address: ", err);
205205
Modal.createTrackedDialog('Unable to verify email address', '', ErrorDialog, {
206206
title: _t("Unable to verify email address."),
207207
description: ((err && err.message) ? err.message : _t("Operation failed")),

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"This email address is already in use": "This email address is already in use",
33
"This phone number is already in use": "This phone number is already in use",
4+
"Add Email Address": "Add Email Address",
45
"Failed to verify email address: make sure you clicked the link in the email": "Failed to verify email address: make sure you clicked the link in the email",
6+
"Add Phone Number": "Add Phone Number",
57
"The platform you're on": "The platform you're on",
68
"The version of Riot.im": "The version of Riot.im",
79
"Whether or not you're logged in (we don't record your username)": "Whether or not you're logged in (we don't record your username)",

0 commit comments

Comments
 (0)