Skip to content

Commit

Permalink
Fixed bug that would prevent the resource code from refreshing tokens…
Browse files Browse the repository at this point in the history
… correctly
  • Loading branch information
djluck committed Apr 7, 2015
1 parent 280151f commit db5639b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand All @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions lib/serverHttp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down

0 comments on commit db5639b

Please sign in to comment.