From ec5f53713dfdecf33a2344264b9e74ab0be36303 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Tue, 16 Sep 2014 20:59:47 -0400 Subject: [PATCH] fix(connection): set token expiration date for GCE 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 --- lib/common/connection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/connection.js b/lib/common/connection.js index 41470241cbae..7244a286b38f 100644 --- a/lib/common/connection.js +++ b/lib/common/connection.js @@ -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;