@@ -468,6 +468,8 @@ util.shouldRetryRequest = shouldRetryRequest;
468
468
* for authenticating API requests.
469
469
*
470
470
* @param {object } config - Configuration object.
471
+ * @param {object= } config.authClient - AuthClient object. If not provided,
472
+ * it will be created and cached here.
471
473
* @param {object= } config.credentials - Credentials object.
472
474
* @param {string= } config.email - Account email address, required for PEM/P12
473
475
* usage.
@@ -476,6 +478,12 @@ util.shouldRetryRequest = shouldRetryRequest;
476
478
* @param {function } callback - The callback function.
477
479
*/
478
480
function getAuthClient ( config , callback ) {
481
+ if ( config . authClient ) {
482
+ setImmediate ( function ( ) {
483
+ callback ( null , config . authClient ) ;
484
+ } ) ;
485
+ return ;
486
+ }
479
487
var googleAuth = new GoogleAuth ( ) ;
480
488
481
489
if ( config . keyFile ) {
@@ -500,6 +508,7 @@ function getAuthClient(config, callback) {
500
508
authClient = authClient . createScoped ( config . scopes ) ;
501
509
}
502
510
511
+ config . authClient = authClient ;
503
512
callback ( null , authClient ) ;
504
513
}
505
514
}
@@ -510,6 +519,8 @@ util.getAuthClient = getAuthClient;
510
519
* Authenticate a request by extending its headers object with an access token.
511
520
*
512
521
* @param {object } config - Configuration object.
522
+ * @param {object= } config.authClient - AuthClient object. If not provided,
523
+ * it will be created and cached here.
513
524
* @param {object= } config.credentials - Credentials object.
514
525
* @param {string= } config.email - Account email address, required for PEM/P12
515
526
* usage.
@@ -563,6 +574,8 @@ util.authorizeRequest = authorizeRequest;
563
574
* response is related to rate limits or certain intermittent server errors.
564
575
* We will exponentially backoff subsequent requests by default. (default:
565
576
* true)
577
+ * @param {object= } config.authClient - AuthClient object. If not provided,
578
+ * it will be created and cached here.
566
579
* @param {object= } config.credentials - Credentials object.
567
580
* @param {boolean= } config.customEndpoint - If true, just return the provided
568
581
* request options. Default: false.
0 commit comments