Skip to content

Commit

Permalink
Merge pull request #661 from ofrobots/patch-1
Browse files Browse the repository at this point in the history
cache auth client
  • Loading branch information
stephenplusplus committed Jun 17, 2015
2 parents c70ce1e + 29f77ce commit c6a4ccd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ util.shouldRetryRequest = shouldRetryRequest;
* for authenticating API requests.
*
* @param {object} config - Configuration object.
* @param {object=} config.authClient - AuthClient object. If not provided,
* it will be created and cached here.
* @param {object=} config.credentials - Credentials object.
* @param {string=} config.email - Account email address, required for PEM/P12
* usage.
Expand All @@ -476,6 +478,12 @@ util.shouldRetryRequest = shouldRetryRequest;
* @param {function} callback - The callback function.
*/
function getAuthClient(config, callback) {
if (config.authClient) {
setImmediate(function() {
callback(null, config.authClient);
});
return;
}
var googleAuth = new GoogleAuth();

if (config.keyFile) {
Expand All @@ -500,6 +508,7 @@ function getAuthClient(config, callback) {
authClient = authClient.createScoped(config.scopes);
}

config.authClient = authClient;
callback(null, authClient);
}
}
Expand All @@ -510,6 +519,8 @@ util.getAuthClient = getAuthClient;
* Authenticate a request by extending its headers object with an access token.
*
* @param {object} config - Configuration object.
* @param {object=} config.authClient - AuthClient object. If not provided,
* it will be created and cached here.
* @param {object=} config.credentials - Credentials object.
* @param {string=} config.email - Account email address, required for PEM/P12
* usage.
Expand Down Expand Up @@ -563,6 +574,8 @@ util.authorizeRequest = authorizeRequest;
* response is related to rate limits or certain intermittent server errors.
* We will exponentially backoff subsequent requests by default. (default:
* true)
* @param {object=} config.authClient - AuthClient object. If not provided,
* it will be created and cached here.
* @param {object=} config.credentials - Credentials object.
* @param {boolean=} config.customEndpoint - If true, just return the provided
* request options. Default: false.
Expand Down

0 comments on commit c6a4ccd

Please sign in to comment.