From 03d0aecc261f333b4bb5d50b2c0b255e533f0831 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Jul 2016 17:24:59 +0100 Subject: [PATCH] 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 ); };