1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Merge pull request #1009 from matrix-org/jryans/user-settings-toggle-3pid

Add API for bulk lookup on the Identity Server
This commit is contained in:
J. Ryan Stinnett
2019-08-07 18:05:58 +01:00
committed by GitHub
2 changed files with 46 additions and 4 deletions

View File

@@ -1891,6 +1891,45 @@ MatrixBaseApis.prototype.lookupThreePid = async function(
} }
}; };
/**
* Looks up the public Matrix ID mappings for multiple 3PIDs.
*
* @param {Array.<Array.<string>>} query Array of arrays containing
* [medium, address]
* @param {string} identityAccessToken The `access_token` field of the Identity
* Server `/account/register` response (see {@link registerWithIdentityServer}).
*
* @return {module:client.Promise} Resolves: Lookup results from IS.
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixBaseApis.prototype.bulkLookupThreePids = async function(
query,
identityAccessToken,
) {
const params = {
threepids: query,
};
try {
return await this._http.idServerRequest(
undefined, "POST", "/bulk_lookup", JSON.stringify(params),
httpApi.PREFIX_IDENTITY_V2, identityAccessToken,
);
} catch (err) {
if (err.cors === "rejected" || err.httpStatus === 404) {
// Fall back to 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
logger.warn("IS doesn't support v2, falling back to deprecated v1");
return await this._http.idServerRequest(
undefined, "POST", "/bulk_lookup", JSON.stringify(params),
httpApi.PREFIX_IDENTITY_V1, identityAccessToken,
);
}
throw err;
}
};
/** /**
* Get account info from the Identity Server. This is useful as a neutral check * Get account info from the Identity Server. This is useful as a neutral check
* to verify that other APIs are likely to approve access by testing that the * to verify that other APIs are likely to approve access by testing that the

View File

@@ -396,16 +396,19 @@ module.exports.MatrixHttpApi.prototype = {
withCredentials: false, withCredentials: false,
json: false, json: false,
_matrix_opts: this.opts, _matrix_opts: this.opts,
headers: {},
}; };
if (method == 'GET') { if (method == 'GET') {
opts.qs = params; opts.qs = params;
} else { } else if (typeof params === "object") {
opts.form = params; opts.form = params;
} else if (typeof params === "string") {
// Assume the caller has serialised the body to JSON
opts.body = params;
opts.headers['Content-Type'] = "application/json";
} }
if (accessToken) { if (accessToken) {
opts.headers = { opts.headers['Authorization'] = `Bearer ${accessToken}`;
Authorization: `Bearer ${accessToken}`,
};
} }
const defer = Promise.defer(); const defer = Promise.defer();