diff --git a/lib/resources.js b/lib/resources.js index de18571..5f27a75 100644 --- a/lib/resources.js +++ b/lib/resources.js @@ -22,7 +22,7 @@ AzureAd.resources.getOrUpdateUserAccessToken = function(friendlyName, user){ function getTokensForResource(user, friendlyName){ return AzureAd.http.getAccessTokensBase(resources[friendlyName], { grant_type: 'refresh_token', - refresh_token: user.services.azureAd.refreshToken + refresh_token: user.azureAdResources[friendlyName].refreshToken || user.services.azureAd.refreshToken }); } @@ -35,7 +35,8 @@ function saveTokensForUser(user, friendlyName, tokens){ } function isAccessTokenMissingOrExpired(user, friendlyName){ - return !user.azureAdResources[friendlyName].accessToken || user.azureAdResources[friendlyName].expiresAt >= new Date(); + return !user.azureAdResources[friendlyName].accessToken || + new Date() >= new Date(user.azureAdResources[friendlyName].expiresOn * 1000); } function checkUserIsDefined(user) { diff --git a/lib/serverHttp.js b/lib/serverHttp.js index a624e5f..5645023 100644 --- a/lib/serverHttp.js +++ b/lib/serverHttp.js @@ -9,7 +9,8 @@ AzureAd.http.call = function (method, url, options) { catch (err) { var details = JSON.stringify({ url : url, - requestParams : options.params + options : options, + method : method }); throw new Meteor.Error("azure-active-directory:failed HTTP request", err.message, details); } @@ -19,7 +20,8 @@ AzureAd.http.call = function (method, url, options) { var details = JSON.stringify({ statusCode : response.statusCode, url : url, - requestParams : options.params + options : options, + method : method }); throw new Meteor.Error("azure-active-directory:invalid HTTP response", "Url=" + reason, details); } @@ -30,8 +32,8 @@ AzureAd.http.call = function (method, url, options) { AzureAd.http.callAuthenticated = function (method, url, accessToken, options) { options = options || {}; - options = _.extend(options, { - headers: { Authorization : "Bearer " + accessToken} + options.headers = _.extend(options.headers || {}, { + Authorization : "Bearer " + accessToken }); return AzureAd.http.call(method, url, options);