Skip to content

Commit

Permalink
fix(connection): set token expiration date for GCE
Browse files Browse the repository at this point in the history
A response from the GCE metadata server responds with data in a
different format from that of the GAPIToken() request. Instead of
looking for a property that doesn't exist `token_expires`, we now
calculate the expiration timestamp from `expires_in`.

For more, see [Authenticating from Google Compute Engine][auth].

[auth]:https://developers.google.com/compute/docs/authentication#applications

Fixes #212
  • Loading branch information
stephenplusplus committed Sep 17, 2014
1 parent 959e92e commit 8be5e2d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/common/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Connection.prototype.fetchToken = function(callback) {
callback(err);
return;
}
var exp = new Date(body.token_expires * 1000);
var exp = new Date(Date.now() + body.expires_in / 1000);
callback(null, new Token(body.access_token, exp));
});
return;
Expand Down

0 comments on commit 8be5e2d

Please sign in to comment.