From d98867b810accafd240aa00829ed9d83d533df98 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Sat, 8 Oct 2016 15:28:01 +0100 Subject: [PATCH] User-Interactive auth for delete device Allow app to pass in an auth dict on delete device --- lib/base-apis.js | 11 +++++++++-- spec/integ/matrix-client-methods.spec.js | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/base-apis.js b/lib/base-apis.js index b926e50a3..1580a470c 100644 --- a/lib/base-apis.js +++ b/lib/base-apis.js @@ -747,16 +747,23 @@ MatrixBaseApis.prototype.setDeviceDetails = function(device_id, body) { * Delete the given device * * @param {string} device_id device to delete + * @param {object} auth Optional. Auth data to supply for User-Interactive auth. * @return {module:client.Promise} Resolves: result object * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixBaseApis.prototype.deleteDevice = function(device_id) { +MatrixBaseApis.prototype.deleteDevice = function(device_id, auth) { var path = utils.encodeUri("/devices/$device_id", { $device_id: device_id, }); + var body = {}; + + if (auth) { + body.auth = auth; + } + return this._http.authedRequestWithPrefix( - undefined, "DELETE", path, undefined, undefined, + undefined, "DELETE", path, undefined, body, httpApi.PREFIX_UNSTABLE ); }; diff --git a/spec/integ/matrix-client-methods.spec.js b/spec/integ/matrix-client-methods.spec.js index f3b941cd6..808304970 100644 --- a/spec/integ/matrix-client-methods.spec.js +++ b/spec/integ/matrix-client-methods.spec.js @@ -383,6 +383,23 @@ describe("MatrixClient", function() { httpBackend.flush(); }); }); + + describe("deleteDevice", function() { + var auth = {a: 1}; + it("should pass through an auth dict", function(done) { + httpBackend.when( + "DELETE", "/_matrix/client/unstable/devices/my_device" + ).check(function(req) { + expect(req.data).toEqual({auth: auth}); + }).respond(200); + + client.deleteDevice( + "my_device", auth + ).catch(utils.failTest).done(done); + + httpBackend.flush(); + }); + }); }); function assertObjectContains(obj, expected) {