diff --git a/lib/auth.js b/lib/auth.js index 229a4b9..8f00b77 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -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(); }, diff --git a/test/auth.spec.js b/test/auth.spec.js index b12da76..3686929 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -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() {