Skip to content

Commit

Permalink
Merge pull request #1019 from matrix-org/dbkr/requesttoken_optional_i…
Browse files Browse the repository at this point in the history
…d_server

Make requestToken endpoints work without ID Server
  • Loading branch information
dbkr authored Aug 19, 2019
2 parents b9480e4 + 6843d86 commit 081ff4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"build": "babel -s -d lib src && rimraf dist && mkdir dist && browserify -d browser-index.js | exorcist dist/browser-matrix.js.map > dist/browser-matrix.js && terser -c -m -o dist/browser-matrix.min.js --source-map \"content='dist/browser-matrix.js.map'\" dist/browser-matrix.js",
"dist": "yarn build",
"watch": "watchify -d browser-index.js -o 'exorcist dist/browser-matrix.js.map > dist/browser-matrix.js' -v",
"lint": "eslint --max-warnings 101 src spec",
"lint": "eslint --max-warnings 93 src spec",
"prepare": "yarn clean && yarn build && git rev-parse HEAD > git-revision.txt"
},
"repository": {
Expand Down
46 changes: 21 additions & 25 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3243,14 +3243,9 @@ MatrixClient.prototype.setGuestAccess = function(roomId, opts) {

/**
* Requests an email verification token for the purposes of registration.
* This API proxies the Identity Server /validate/email/requestToken API,
* adding registration-specific behaviour. 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 registration-specific logic.
* This API requests a token from the homeserver.
* The doesServerRequireIdServerParam() method can be used to determine if
* the server requires the id_server parameter to be provided.
*
* Parameters and return value are as for requestEmailToken
Expand All @@ -3275,8 +3270,9 @@ MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret,

/**
* Requests a text message verification token for the purposes of registration.
* This API proxies the Identity Server /validate/msisdn/requestToken API,
* adding registration-specific behaviour, as with requestRegisterEmailToken.
* This API requests a token from the homeserver.
* 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
* phoneNumber should be parsed relative to.
Expand All @@ -3303,15 +3299,13 @@ MatrixClient.prototype.requestRegisterMsisdnToken = function(phoneCountry, phone
/**
* 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.
* This API requests a token from the homeserver.
* The doesServerRequireIdServerParam() method can be used to determine if
* the server requires the id_server parameter to be provided.
* If an account with the given email address already exists and is
* associated with an account other than the one the user is authed as,
* 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).
*
* @param {string} email As requestEmailToken
* @param {string} clientSecret As requestEmailToken
Expand Down Expand Up @@ -3428,14 +3422,16 @@ MatrixClient.prototype.requestPasswordMsisdnToken = function(phoneCountry, phone
* @return {module:client.Promise} Resolves: As requestEmailToken
*/
MatrixClient.prototype._requestTokenFromEndpoint = function(endpoint, params) {
const id_server_url = url.parse(this.idBaseUrl);
if (id_server_url.host === null) {
throw new Error("Invalid ID server URL: " + this.idBaseUrl);
const postParams = Object.assign({}, params);

if (this.idBaseUrl) {
const idServerUrl = url.parse(this.idBaseUrl);
if (!idServerUrl.host) {
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(
undefined, "POST", endpoint, undefined,
postParams,
Expand Down

0 comments on commit 081ff4d

Please sign in to comment.