@@ -377,32 +377,37 @@ Service_.prototype.handleCallback = function(callbackRequest) {
377
377
*/
378
378
Service_ . prototype . hasAccess = function ( ) {
379
379
var token = this . getToken ( ) ;
380
- if ( ! token || this . isExpired_ ( token ) ) {
381
- return this . lockable_ ( function ( ) {
382
- // Get the token again, bypassing the local memory cache.
383
- token = this . getToken ( true ) ;
384
- // Check to see if the token is still missing or expired, as another
385
- // execution may have refreshed it while we were waiting for the lock.
386
- if ( ! token || this . isExpired_ ( token ) ) {
387
- try {
388
- if ( token && this . canRefresh_ ( token ) ) {
389
- this . refresh ( ) ;
390
- } else if ( this . privateKey_ ) {
391
- this . exchangeJwt_ ( ) ;
392
- } else if ( this . grantType_ ) {
393
- this . exchangeGrant_ ( ) ;
394
- } else {
395
- return false ;
396
- }
397
- } catch ( e ) {
398
- this . lastError_ = e ;
399
- return false ;
400
- }
380
+ if ( token && ! this . isExpired_ ( token ) ) return true ; // Token still has access.
381
+ var canGetToken = ( token && this . canRefresh_ ( token ) ) ||
382
+ this . privateKey_ || this . grantType_ ;
383
+ if ( ! canGetToken ) return false ;
384
+
385
+ return this . lockable_ ( function ( ) {
386
+ // Get the token again, bypassing the local memory cache.
387
+ token = this . getToken ( true ) ;
388
+ // Check to see if the token is no longer missing or expired, as another
389
+ // execution may have refreshed it while we were waiting for the lock.
390
+ if ( token && ! this . isExpired_ ( token ) ) return true ; // Token now has access.
391
+ try {
392
+ if ( token && this . canRefresh_ ( token ) ) {
393
+ this . refresh ( ) ;
394
+ return true ;
395
+ } else if ( this . privateKey_ ) {
396
+ this . exchangeJwt_ ( ) ;
397
+ return true ;
398
+ } else if ( this . grantType_ ) {
399
+ this . exchangeGrant_ ( ) ;
400
+ return true ;
401
+ } else {
402
+ // This should never happen, since canGetToken should have been false
403
+ // earlier.
404
+ return false ;
401
405
}
402
- return true ;
403
- } ) ;
404
- }
405
- return true ;
406
+ } catch ( e ) {
407
+ this . lastError_ = e ;
408
+ return false ;
409
+ }
410
+ } ) ;
406
411
} ;
407
412
408
413
/**
@@ -586,12 +591,13 @@ Service_.prototype.saveToken_ = function(token) {
586
591
587
592
/**
588
593
* Gets the token from the service's property store or cache.
589
- * @param {boolean } optSkipMemory Whether to bypass the local memory cache when
590
- * fetching the token (the default is false) .
594
+ * @param {boolean? } optSkipMemoryCheck If true, bypass the local memory cache
595
+ * when fetching the token.
591
596
* @return {Object } The token, or null if no token was found.
592
597
*/
593
- Service_ . prototype . getToken = function ( optSkipMemory ) {
594
- return this . getStorage ( ) . getValue ( null , optSkipMemory ) ;
598
+ Service_ . prototype . getToken = function ( optSkipMemoryCheck ) {
599
+ // Gets the stored value under the null key, which is reserved for the token.
600
+ return this . getStorage ( ) . getValue ( null , optSkipMemoryCheck ) ;
595
601
} ;
596
602
597
603
/**
0 commit comments