Skip to content

Commit

Permalink
update the expires offset from 2 to 5 minutes, use default value for …
Browse files Browse the repository at this point in the history
…"expires_in"
  • Loading branch information
tushargupta51 committed Feb 8, 2017
1 parent 862b13d commit 467bd53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/adal.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ var AuthenticationContext = (function () {
var expiry = this._getItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY + resource);

// If expiration is within offset, it will force renew
var offset = this.config.expireOffsetSeconds || 120;
var offset = this.config.expireOffsetSeconds || 300;

if (expiry && (expiry > this._now() + offset)) {
return token;
Expand Down Expand Up @@ -1267,6 +1267,8 @@ var AuthenticationContext = (function () {
* @ignore
*/
AuthenticationContext.prototype._expiresIn = function (expires) {
// if AAD did not send "expires_in" property, use default expiration of 3599 seconds, for some reason AAD sends 3599 as "expires_in" value
if (!expires) expires = 3599;
return this._now() + parseInt(expires, 10);
};

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/spec/AdalSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,4 +1033,16 @@ describe('Adal', function () {
Logging.level = 2;

});

it('tests default value for expires_in', function () {
var requestInfo = {
valid: true,
parameters: { 'access_token': 'token123', 'state': '123' },
stateMatch: true,
stateResponse: '123|loginResource1',
requestType: adal.REQUEST_TYPE.RENEW_TOKEN
};
adal.saveTokenFromHash(requestInfo);
expect(storageFake.getItem(adal.CONSTANTS.STORAGE.EXPIRATION_KEY + 'loginResource1')).toBe(mathMock.round(1) + 3599);
});
});

0 comments on commit 467bd53

Please sign in to comment.