Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Delete AccessTokenAuthenticator access token #605

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,33 @@ Client.prototype.getResource = function() {
return this._dataStore.getResource.apply(this._dataStore, arguments);
};

/**
* @private
*
* @callback deleteResourceCallback
*
* @param {Error} err
* The error (if there is one).
*/

/**
* Deletes a given resource by href.
*
* @private
*
* @param {Object} resource
* The resource to be deleted.
*
* @param {String} resource.href
* The URI of the resource.
*
* @param {getResourceCallback}
* The callback that handles the response.
*/
Client.prototype.deleteResource = function deleteResource() {
return this._dataStore.deleteResource.apply(this._dataStore, arguments);
};

/**
* @private
*
Expand Down
13 changes: 13 additions & 0 deletions lib/oauth/stormpath-access-token-authentication-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,17 @@ StormpathAccessTokenAuthenticationResult.prototype.getApplication = function get
this.client.getApplication(this.application.href, args.options, require('../resource/Application'), args.callback);
};

/**
* @function
*
* @description Delete the access token used to authenticate.
*
* @param {Function} callback
* The callback to call after the resource is deleted, with parameters (err, null)
*/
StormpathAccessTokenAuthenticationResult.prototype.deleteAccessToken = function deleteAccessToken(/* callback */) {
var args = utils.resolveArgs(arguments, ['callback']);
this.client.deleteResource({href: this.href}, args.callback);
};

module.exports = StormpathAccessTokenAuthenticationResult;
44 changes: 44 additions & 0 deletions test/sp.client_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,50 @@ describe('Client', function () {
});
});

describe('call to delete resource', function () {
var sandbox;
var client;
var deleteResourceStub;
var cbSpy;
var resource;

before(function (done) {
resource = {href: '/boom!'};
sandbox = sinon.sandbox.create();
client = makeTestClient({apiKey: apiKey});

client.on('error', function (err) {
throw err;
});

client.on('ready', function () {
deleteResourceStub = sandbox.stub(client._dataStore, 'deleteResource', function (resource, cb) {
cb();
});

cbSpy = sandbox.spy();

done();
});
});

after(function () {
sandbox.restore();
});

it('should call dataStore#deleteResource', function () {
client.deleteResource(resource, cbSpy);

deleteResourceStub.should.have.been
.calledWith(resource, cbSpy);

/* jshint -W030 */
deleteResourceStub.should.have.been.calledOnce;
cbSpy.should.have.been.calledOnce;
/* jshint +W030 */
});
});

describe('call to get accounts', function() {
var cbSpy, client, err, sandbox, tenant;
var getCurrentTenantStub, getTenantAccounts;
Expand Down