Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.
Merged
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
12 changes: 12 additions & 0 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ module.exports = {
}.bind(this));
},

authenticateWithApp: function(appId, appToken, callback) {
var requestData = {
grant_type: 'app',
app_id: appId,
app_token: appToken
};

this._authenticate(requestData, function(responseData) {
this._onAccessTokenAcquired(responseData, callback);
}.bind(this));
},

refreshAuthFromStore: function() {
this._getAuthFromStore();
},
Expand Down
34 changes: 34 additions & 0 deletions test/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,40 @@ describe('auth', function() {

});

describe('authenticateWithApp', function() {

it('should call _authenticate with appId, appToken and correct grand type', function() {
var host = {
_authenticate: sinon.stub()
};
var expectedData = {
grant_type: 'app',
app_id: 123,
app_token: 'e123'
};

auth.authenticateWithApp.call(host, 123, 'e123');

expect(host._authenticate.calledOnce).toBe(true);
expect(host._authenticate.getCall(0).args[0]).toEqual(expectedData);
});

it('should call _onAccessTokenAcquired with responseData and callback when auth is completed', function() {
var authData = { access_token: 'a321' };
var callback = function() {};
var host = {
_authenticate: sinon.stub().callsArgWith(1, authData),
_onAccessTokenAcquired: sinon.stub()
};

auth.authenticateWithApp.call(host, 123, 'e123', callback);

expect(host._onAccessTokenAcquired.calledOnce).toBe(true);
expect(host._onAccessTokenAcquired.calledWithExactly(authData, callback)).toBe(true);
});

});

describe('_getAuthFromStore', function() {

it('should get auth data from the session store and store it in memory', function() {
Expand Down