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

Make requestToken endpoints work without ID Server

Hopefully with doc in appropriate functions
This commit is contained in:
David Baker
2019-08-16 18:09:29 +01:00
parent b9480e4302
commit 852304c417

View File

@@ -3243,14 +3243,9 @@ MatrixClient.prototype.setGuestAccess = function(roomId, opts) {
/** /**
* Requests an email verification token for the purposes of registration. * Requests an email verification token for the purposes of registration.
* This API proxies the Identity Server /validate/email/requestToken API, * This API requests a token from the homeserver.
* adding registration-specific behaviour. Specifically, if an account with * The doesServerRequireIdServerParam() method can be used to determine if
* the given email address already exists, it will either send an email * the server requires the id_server parameter to be provided.
* to the address informing them of this or return M_THREEPID_IN_USE
* (which one is up to the Home Server).
*
* requestEmailToken calls the equivalent API directly on the ID server,
* therefore bypassing the registration-specific logic.
* *
* Parameters and return value are as for requestEmailToken * Parameters and return value are as for requestEmailToken
@@ -3275,8 +3270,9 @@ MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret,
/** /**
* Requests a text message verification token for the purposes of registration. * Requests a text message verification token for the purposes of registration.
* This API proxies the Identity Server /validate/msisdn/requestToken API, * This API requests a token from the homeserver.
* adding registration-specific behaviour, as with requestRegisterEmailToken. * The doesServerRequireIdServerParam() method can be used to determine if
* the server requires the id_server parameter to be provided.
* *
* @param {string} phoneCountry The ISO 3166-1 alpha-2 code for the country in which * @param {string} phoneCountry The ISO 3166-1 alpha-2 code for the country in which
* phoneNumber should be parsed relative to. * phoneNumber should be parsed relative to.
@@ -3303,15 +3299,13 @@ MatrixClient.prototype.requestRegisterMsisdnToken = function(phoneCountry, phone
/** /**
* Requests an email verification token for the purposes of adding a * Requests an email verification token for the purposes of adding a
* third party identifier to an account. * third party identifier to an account.
* This API proxies the Identity Server /validate/email/requestToken API, * This API requests a token from the homeserver.
* adding specific behaviour for the addition of email addresses to an * The doesServerRequireIdServerParam() method can be used to determine if
* account. Specifically, if an account with * the server requires the id_server parameter to be provided.
* the given email address already exists, it will either send an email * If an account with the given email address already exists and is
* to the address informing them of this or return M_THREEPID_IN_USE * associated with an account other than the one the user is authed as,
* (which one is up to the Home Server). * it will either send an email to the address informing them of this
* * or return M_THREEPID_IN_USE (which one is up to the Home Server).
* requestEmailToken calls the equivalent API directly on the ID server,
* therefore bypassing the email addition specific logic.
* *
* @param {string} email As requestEmailToken * @param {string} email As requestEmailToken
* @param {string} clientSecret As requestEmailToken * @param {string} clientSecret As requestEmailToken
@@ -3428,14 +3422,16 @@ MatrixClient.prototype.requestPasswordMsisdnToken = function(phoneCountry, phone
* @return {module:client.Promise} Resolves: As requestEmailToken * @return {module:client.Promise} Resolves: As requestEmailToken
*/ */
MatrixClient.prototype._requestTokenFromEndpoint = function(endpoint, params) { MatrixClient.prototype._requestTokenFromEndpoint = function(endpoint, params) {
const id_server_url = url.parse(this.idBaseUrl); const postParams = Object.assign({}, params);
if (id_server_url.host === null) {
if (this.idBaseUrl) {
const idServerUrl = url.parse(this.idBaseUrl);
if (idServerUrl.host === null) {
throw new Error("Invalid ID server URL: " + this.idBaseUrl); throw new Error("Invalid ID server URL: " + this.idBaseUrl);
} }
postParams.id_server = idServerUrl.host;
}
const postParams = Object.assign({}, params, {
id_server: id_server_url.host,
});
return this._http.request( return this._http.request(
undefined, "POST", endpoint, undefined, undefined, "POST", endpoint, undefined,
postParams, postParams,