Merge pull request #3466 from matrix-org/jryans/msisdn-submit-url
Use alternate MSISDN submit URL when returned by HSpull/21833/head
commit
2c7c1ed2a3
|
@ -35,6 +35,8 @@ import IdentityAuthClient from './IdentityAuthClient';
|
||||||
export default class AddThreepid {
|
export default class AddThreepid {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.clientSecret = MatrixClientPeg.get().generateClientSecret();
|
this.clientSecret = MatrixClientPeg.get().generateClientSecret();
|
||||||
|
this.sessionId = null;
|
||||||
|
this.submitUrl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,6 +103,7 @@ export default class AddThreepid {
|
||||||
phoneCountry, phoneNumber, this.clientSecret, 1,
|
phoneCountry, phoneNumber, this.clientSecret, 1,
|
||||||
).then((res) => {
|
).then((res) => {
|
||||||
this.sessionId = res.sid;
|
this.sessionId = res.sid;
|
||||||
|
this.submitUrl = res.submit_url;
|
||||||
return res;
|
return res;
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err.errcode === 'M_THREEPID_IN_USE') {
|
if (err.errcode === 'M_THREEPID_IN_USE') {
|
||||||
|
@ -197,13 +200,23 @@ export default class AddThreepid {
|
||||||
*/
|
*/
|
||||||
async haveMsisdnToken(msisdnToken) {
|
async haveMsisdnToken(msisdnToken) {
|
||||||
const authClient = new IdentityAuthClient();
|
const authClient = new IdentityAuthClient();
|
||||||
const identityAccessToken = await authClient.getAccessToken();
|
|
||||||
const result = await MatrixClientPeg.get().submitMsisdnToken(
|
let result;
|
||||||
this.sessionId,
|
if (this.submitUrl) {
|
||||||
this.clientSecret,
|
result = await MatrixClientPeg.get().submitMsisdnTokenOtherUrl(
|
||||||
msisdnToken,
|
this.submitUrl,
|
||||||
identityAccessToken,
|
this.sessionId,
|
||||||
);
|
this.clientSecret,
|
||||||
|
msisdnToken,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
result = await MatrixClientPeg.get().submitMsisdnToken(
|
||||||
|
this.sessionId,
|
||||||
|
this.clientSecret,
|
||||||
|
msisdnToken,
|
||||||
|
await authClient.getAccessToken(),
|
||||||
|
);
|
||||||
|
}
|
||||||
if (result.errcode) {
|
if (result.errcode) {
|
||||||
throw result;
|
throw result;
|
||||||
}
|
}
|
||||||
|
@ -211,13 +224,11 @@ export default class AddThreepid {
|
||||||
const identityServerDomain = MatrixClientPeg.get().idBaseUrl.split("://")[1];
|
const identityServerDomain = MatrixClientPeg.get().idBaseUrl.split("://")[1];
|
||||||
if (await MatrixClientPeg.get().doesServerSupportSeparateAddAndBind()) {
|
if (await MatrixClientPeg.get().doesServerSupportSeparateAddAndBind()) {
|
||||||
if (this.bind) {
|
if (this.bind) {
|
||||||
const authClient = new IdentityAuthClient();
|
|
||||||
const identityAccessToken = await authClient.getAccessToken();
|
|
||||||
await MatrixClientPeg.get().bindThreePid({
|
await MatrixClientPeg.get().bindThreePid({
|
||||||
sid: this.sessionId,
|
sid: this.sessionId,
|
||||||
client_secret: this.clientSecret,
|
client_secret: this.clientSecret,
|
||||||
id_server: identityServerDomain,
|
id_server: identityServerDomain,
|
||||||
id_access_token: identityAccessToken,
|
id_access_token: await authClient.getAccessToken(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await MatrixClientPeg.get().addThreePidOnly({
|
await MatrixClientPeg.get().addThreePidOnly({
|
||||||
|
|
Loading…
Reference in New Issue