Guard against misconfigured homeservers when adding / binding phone numbers
This ensures we only fallback to submitting MSISDN tokens to the identity server when we expect to do. Unexpected cases will now throw an error. Fixes https://github.com/vector-im/riot-web/issues/10936pull/21833/head
parent
54cea6a5e3
commit
b38c7fc411
|
@ -236,6 +236,8 @@ export default class AddThreepid {
|
||||||
*/
|
*/
|
||||||
async haveMsisdnToken(msisdnToken) {
|
async haveMsisdnToken(msisdnToken) {
|
||||||
const authClient = new IdentityAuthClient();
|
const authClient = new IdentityAuthClient();
|
||||||
|
const supportsSeparateAddAndBind =
|
||||||
|
await MatrixClientPeg.get().doesServerSupportSeparateAddAndBind();
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
if (this.submitUrl) {
|
if (this.submitUrl) {
|
||||||
|
@ -245,19 +247,21 @@ export default class AddThreepid {
|
||||||
this.clientSecret,
|
this.clientSecret,
|
||||||
msisdnToken,
|
msisdnToken,
|
||||||
);
|
);
|
||||||
} else {
|
} else if (this.bind || !supportsSeparateAddAndBind) {
|
||||||
result = await MatrixClientPeg.get().submitMsisdnToken(
|
result = await MatrixClientPeg.get().submitMsisdnToken(
|
||||||
this.sessionId,
|
this.sessionId,
|
||||||
this.clientSecret,
|
this.clientSecret,
|
||||||
msisdnToken,
|
msisdnToken,
|
||||||
await authClient.getAccessToken(),
|
await authClient.getAccessToken(),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
throw new Error("The add / bind with MSISDN flow is misconfigured");
|
||||||
}
|
}
|
||||||
if (result.errcode) {
|
if (result.errcode) {
|
||||||
throw result;
|
throw result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await MatrixClientPeg.get().doesServerSupportSeparateAddAndBind()) {
|
if (supportsSeparateAddAndBind) {
|
||||||
if (this.bind) {
|
if (this.bind) {
|
||||||
await MatrixClientPeg.get().bindThreePid({
|
await MatrixClientPeg.get().bindThreePid({
|
||||||
sid: this.sessionId,
|
sid: this.sessionId,
|
||||||
|
|
|
@ -475,22 +475,26 @@ export const MsisdnAuthEntry = createReactClass({
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const requiresIdServerParam =
|
||||||
|
await this.props.matrixClient.doesServerRequireIdServerParam();
|
||||||
let result;
|
let result;
|
||||||
if (this._submitUrl) {
|
if (this._submitUrl) {
|
||||||
result = await this.props.matrixClient.submitMsisdnTokenOtherUrl(
|
result = await this.props.matrixClient.submitMsisdnTokenOtherUrl(
|
||||||
this._submitUrl, this._sid, this.props.clientSecret, this.state.token,
|
this._submitUrl, this._sid, this.props.clientSecret, this.state.token,
|
||||||
);
|
);
|
||||||
} else {
|
} else if (requiresIdServerParam) {
|
||||||
result = await this.props.matrixClient.submitMsisdnToken(
|
result = await this.props.matrixClient.submitMsisdnToken(
|
||||||
this._sid, this.props.clientSecret, this.state.token,
|
this._sid, this.props.clientSecret, this.state.token,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
throw new Error("The registration with MSISDN flow is misconfigured");
|
||||||
}
|
}
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const creds = {
|
const creds = {
|
||||||
sid: this._sid,
|
sid: this._sid,
|
||||||
client_secret: this.props.clientSecret,
|
client_secret: this.props.clientSecret,
|
||||||
};
|
};
|
||||||
if (await this.props.matrixClient.doesServerRequireIdServerParam()) {
|
if (requiresIdServerParam) {
|
||||||
const idServerParsedUrl = url.parse(
|
const idServerParsedUrl = url.parse(
|
||||||
this.props.matrixClient.getIdentityServerUrl(),
|
this.props.matrixClient.getIdentityServerUrl(),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue