From 03d0aecc261f333b4bb5d50b2c0b255e533f0831 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Jul 2016 17:24:59 +0100 Subject: [PATCH 1/4] Add API calls for other requestToken endpoints --- lib/client.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 8b0867771..7d0fe45bd 100644 --- a/lib/client.js +++ b/lib/client.js @@ -2807,6 +2807,61 @@ MatrixClient.prototype.register = function(username, password, */ MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret, sendAttempt, nextLink, callback) { + return this._requestTokenFromEndpoint( + "/register/email/requestToken", email, clientSecret, sendAttempt, nextLink, callback + ); +}; + +/** + * Requests an email verification token for the purposes of adding a + * third party identifier to an account. + * This API proxies the Identity Server /validate/email/requestToken API, + * adding specific behaviour for the addition of email addresses to an + * account. Specifically, if an account with + * the given email address already exists, 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. + * + * Parameters and return value are as for requestEmailToken + */ +MatrixClient.prototype.request3pidAddEmailToken = function(email, clientSecret, + sendAttempt, nextLink, callback) { + return this._requestTokenFromEndpoint( + "/account/3pid/email/requestToken", email, clientSecret, sendAttempt, nextLink, callback + ); +}; + +/** + * Requests an email verification token for the purposes of resetting + * the password on an account. + * This API proxies the Identity Server /validate/email/requestToken API, + * adding specific behaviour for the password resetting. Specifically, + * if no account with the given email address exists, it may either + * return M_THREEPID_NOT_FOUND or send an email + * to the address informing them of this (which one is up to the Home Server). + * + * requestEmailToken calls the equivalent API directly on the ID server, + * therefore bypassing the password reset specific logic. + * + * Parameters and return value are as for requestEmailToken + */ +MatrixClient.prototype.requestPasswordEmailToken = function(email, clientSecret, + sendAttempt, nextLink, callback) { + return this._requestTokenFromEndpoint( + "/account/password/email/requestToken", email, clientSecret, sendAttempt, nextLink, callback + ); +}; + +/** + * Internal utility function for requesting validation tokens from usage-specific + * requestToken endpoints. + */ +MatrixClient.prototype._requestTokenFromEndpoint = function(endpoint, + email, clientSecret, + sendAttempt, nextLink, callback) { var id_server_url = url.parse(this.idBaseUrl); if (id_server_url.host === null) { throw new Error("Invalid ID server URL: " + this.idBaseUrl); @@ -2820,7 +2875,7 @@ MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret, id_server: id_server_url.host, }; return this._http.request( - callback, "POST", "/register/email/requestToken", undefined, + callback, "POST", endpoint, undefined, params ); }; From 425039c5b5c1123b4be32b77b18d68c7c385dd40 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Jul 2016 17:26:23 +0100 Subject: [PATCH 2/4] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24ce6919b..b36b94b4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Changes in \ ======================= * Add room.getAliases() and room.getCanonicalAlias + * Add API calls `/register/email/requestToken`, `/account/password/email/requestToken` and `/account/3pid/email/requestToken` Changes in [0.5.4](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.5.4) (2016-06-02) ================================================================================================ From 7dbc03942a71d3be854b0851971cc72c7aa51d79 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Jul 2016 17:35:37 +0100 Subject: [PATCH 3/4] linty lint lint --- lib/client.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/client.js b/lib/client.js index 7d0fe45bd..83165d545 100644 --- a/lib/client.js +++ b/lib/client.js @@ -2808,7 +2808,8 @@ MatrixClient.prototype.register = function(username, password, MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret, sendAttempt, nextLink, callback) { return this._requestTokenFromEndpoint( - "/register/email/requestToken", email, clientSecret, sendAttempt, nextLink, callback + "/register/email/requestToken", + email, clientSecret, sendAttempt, nextLink, callback ); }; @@ -2825,12 +2826,18 @@ MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret, * requestEmailToken calls the equivalent API directly on the ID server, * therefore bypassing the email addition specific logic. * - * Parameters and return value are as for requestEmailToken + * @param {string} email As requestEmailToken + * @param {string} clientSecret As requestEmailToken + * @param {number} sendAttempt As requestEmailToken + * @param {string} nextLink As requestEmailToken + * @param {module:client.callback} callback Optional. As requestEmailToken + * @return {module:client.Promise} Resolves: As requestEmailToken */ MatrixClient.prototype.request3pidAddEmailToken = function(email, clientSecret, sendAttempt, nextLink, callback) { return this._requestTokenFromEndpoint( - "/account/3pid/email/requestToken", email, clientSecret, sendAttempt, nextLink, callback + "/account/3pid/email/requestToken", + email, clientSecret, sendAttempt, nextLink, callback ); }; @@ -2846,18 +2853,32 @@ MatrixClient.prototype.request3pidAddEmailToken = function(email, clientSecret, * requestEmailToken calls the equivalent API directly on the ID server, * therefore bypassing the password reset specific logic. * - * Parameters and return value are as for requestEmailToken + * @param {string} email As requestEmailToken + * @param {string} clientSecret As requestEmailToken + * @param {number} sendAttempt As requestEmailToken + * @param {string} nextLink As requestEmailToken + * @param {module:client.callback} callback Optional. As requestEmailToken + * @return {module:client.Promise} Resolves: As requestEmailToken */ MatrixClient.prototype.requestPasswordEmailToken = function(email, clientSecret, sendAttempt, nextLink, callback) { return this._requestTokenFromEndpoint( - "/account/password/email/requestToken", email, clientSecret, sendAttempt, nextLink, callback + "/account/password/email/requestToken", + email, clientSecret, sendAttempt, nextLink, callback ); }; /** * Internal utility function for requesting validation tokens from usage-specific * requestToken endpoints. + * + * @param {string} endpoint The endpoint to send the request to + * @param {string} email As requestEmailToken + * @param {string} clientSecret As requestEmailToken + * @param {number} sendAttempt As requestEmailToken + * @param {string} nextLink As requestEmailToken + * @param {module:client.callback} callback Optional. As requestEmailToken + * @return {module:client.Promise} Resolves: As requestEmailToken */ MatrixClient.prototype._requestTokenFromEndpoint = function(endpoint, email, clientSecret, From b689dbb9c0fc377cfd710ca53fbf6250a6cc47e2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Jul 2016 17:52:27 +0100 Subject: [PATCH 4/4] Better function name --- lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 83165d545..ea0a67720 100644 --- a/lib/client.js +++ b/lib/client.js @@ -2833,7 +2833,7 @@ MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret, * @param {module:client.callback} callback Optional. As requestEmailToken * @return {module:client.Promise} Resolves: As requestEmailToken */ -MatrixClient.prototype.request3pidAddEmailToken = function(email, clientSecret, +MatrixClient.prototype.requestAdd3pidEmailToken = function(email, clientSecret, sendAttempt, nextLink, callback) { return this._requestTokenFromEndpoint( "/account/3pid/email/requestToken",