You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Add first pass of IS v2 API with authentication
This only updates the `/lookup` API so far. It also doesn't handle falling back to v1.
This commit is contained in:
@@ -1701,6 +1701,27 @@ MatrixBaseApis.prototype.getKeyChanges = function(oldToken, newToken) {
|
|||||||
// Identity Server Operations
|
// Identity Server Operations
|
||||||
// ==========================
|
// ==========================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register with an Identity Server using the OpenID token from the user's
|
||||||
|
* Homeserver, which can be retrieved via
|
||||||
|
* {@link module:client~MatrixClient#getOpenIdToken}.
|
||||||
|
*
|
||||||
|
* Note that the `/account/register` endpoint (as well as IS authentication in
|
||||||
|
* general) was added as part of the v2 API version.
|
||||||
|
*
|
||||||
|
* @param {object} hsOpenIdToken
|
||||||
|
* @return {module:client.Promise} Resolves: with object containing an Identity
|
||||||
|
* Server access token.
|
||||||
|
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||||
|
*/
|
||||||
|
MatrixBaseApis.prototype.registerWithIdentityServer = function(hsOpenIdToken) {
|
||||||
|
const uri = this.idBaseUrl + httpApi.PREFIX_IDENTITY_V2 + "/account/register";
|
||||||
|
return this._http.requestOtherUrl(
|
||||||
|
undefined, "POST", uri,
|
||||||
|
null, hsOpenIdToken,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests an email verification token directly from an Identity Server.
|
* Requests an email verification token directly from an Identity Server.
|
||||||
*
|
*
|
||||||
@@ -1767,22 +1788,33 @@ MatrixBaseApis.prototype.submitMsisdnToken = function(sid, clientSecret, token)
|
|||||||
/**
|
/**
|
||||||
* Looks up the public Matrix ID mapping for a given 3rd party
|
* Looks up the public Matrix ID mapping for a given 3rd party
|
||||||
* identifier from the Identity Server
|
* identifier from the Identity Server
|
||||||
|
*
|
||||||
* @param {string} medium The medium of the threepid, eg. 'email'
|
* @param {string} medium The medium of the threepid, eg. 'email'
|
||||||
* @param {string} address The textual address of the threepid
|
* @param {string} address The textual address of the threepid
|
||||||
* @param {module:client.callback} callback Optional.
|
* @param {module:client.callback} callback Optional.
|
||||||
|
* @param {string} isAccessToken The `access_token` field of the Identity Server
|
||||||
|
* `/account/register` response (see {@link registerWithIdentityServer}).
|
||||||
|
*
|
||||||
* @return {module:client.Promise} Resolves: A threepid mapping
|
* @return {module:client.Promise} Resolves: A threepid mapping
|
||||||
* object or the empty object if no mapping
|
* object or the empty object if no mapping
|
||||||
* exists
|
* exists
|
||||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||||
*/
|
*/
|
||||||
MatrixBaseApis.prototype.lookupThreePid = function(medium, address, callback) {
|
MatrixBaseApis.prototype.lookupThreePid = function(
|
||||||
|
medium,
|
||||||
|
address,
|
||||||
|
callback,
|
||||||
|
isAccessToken,
|
||||||
|
) {
|
||||||
const params = {
|
const params = {
|
||||||
medium: medium,
|
medium: medium,
|
||||||
address: address,
|
address: address,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: Testing only - add fallback to v1
|
||||||
return this._http.idServerRequest(
|
return this._http.idServerRequest(
|
||||||
callback, "GET", "/lookup",
|
callback, "GET", "/lookup",
|
||||||
params, httpApi.PREFIX_IDENTITY_V1,
|
params, httpApi.PREFIX_IDENTITY_V2, isAccessToken,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -374,7 +374,14 @@ module.exports.MatrixHttpApi.prototype = {
|
|||||||
return this.uploads;
|
return this.uploads;
|
||||||
},
|
},
|
||||||
|
|
||||||
idServerRequest: function(callback, method, path, params, prefix) {
|
idServerRequest: function(
|
||||||
|
callback,
|
||||||
|
method,
|
||||||
|
path,
|
||||||
|
params,
|
||||||
|
prefix,
|
||||||
|
accessToken,
|
||||||
|
) {
|
||||||
const fullUri = this.opts.idBaseUrl + prefix + path;
|
const fullUri = this.opts.idBaseUrl + prefix + path;
|
||||||
|
|
||||||
if (callback !== undefined && !utils.isFunction(callback)) {
|
if (callback !== undefined && !utils.isFunction(callback)) {
|
||||||
@@ -395,6 +402,11 @@ module.exports.MatrixHttpApi.prototype = {
|
|||||||
} else {
|
} else {
|
||||||
opts.form = params;
|
opts.form = params;
|
||||||
}
|
}
|
||||||
|
if (accessToken) {
|
||||||
|
opts.headers = {
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const defer = Promise.defer();
|
const defer = Promise.defer();
|
||||||
this.opts.request(
|
this.opts.request(
|
||||||
|
|||||||
Reference in New Issue
Block a user