@@ -256,7 +256,7 @@ function test(utils) {
256
256
} )
257
257
. then ( function ( user ) {
258
258
// Get the user's ID token.
259
- return user . getToken ( ) ;
259
+ return user . getIdToken ( ) ;
260
260
} )
261
261
. then ( function ( idToken ) {
262
262
// Verify ID token contents.
@@ -418,7 +418,7 @@ function test(utils) {
418
418
return firebase . auth ( ) . signInWithCustomToken ( customToken ) ;
419
419
} )
420
420
. then ( function ( user ) {
421
- return user . getToken ( ) ;
421
+ return user . getIdToken ( ) ;
422
422
} )
423
423
. then ( function ( idToken ) {
424
424
utils . logSuccess ( 'auth.createCustomToken()' ) ;
@@ -449,11 +449,78 @@ function test(utils) {
449
449
} ) ;
450
450
}
451
451
452
+ function testRefreshTokenRevocation ( ) {
453
+ var currentIdToken = null ;
454
+ var currentUser = null ;
455
+ // Sign in with an email and password account.
456
+ return firebase . auth ( ) . signInWithEmailAndPassword ( mockUserData . email , mockUserData . password )
457
+ . then ( function ( user ) {
458
+ currentUser = user ;
459
+ // Get user's ID token.
460
+ return user . getIdToken ( ) ;
461
+ } )
462
+ . then ( function ( idToken ) {
463
+ currentIdToken = idToken ;
464
+ // Verify that user's ID token while checking for revocation.
465
+ return admin . auth ( ) . verifyIdToken ( currentIdToken , true )
466
+ } )
467
+ . then ( function ( decodedIdToken ) {
468
+ // Verification should succeed. Revoke that user's session.
469
+ return admin . auth ( ) . revokeRefreshTokens ( decodedIdToken . sub ) ;
470
+ } )
471
+ . then ( function ( ) {
472
+ // verifyIdToken without checking revocation should still succeed.
473
+ return admin . auth ( ) . verifyIdToken ( currentIdToken ) ;
474
+ } )
475
+ . then ( function ( ) {
476
+ // verifyIdToken while checking for revocation should fail.
477
+ return admin . auth ( ) . verifyIdToken ( currentIdToken , true )
478
+ . then ( function ( decodedIdToken ) {
479
+ throw new Error ( 'verifyIdToken(revoked, true) succeeded' ) ;
480
+ } )
481
+ . catch ( function ( error ) {
482
+ utils . assert (
483
+ error . code === 'auth/id-token-revoked' ,
484
+ 'auth().verifyIdToken(revokedIdToken, true)' ,
485
+ 'Expected auth/id-token-revoked was not thrown' ) ;
486
+ } ) ;
487
+ } )
488
+ . then ( function ( ) {
489
+ // Confirm token revoked on client.
490
+ return currentUser . reload ( )
491
+ . then ( function ( ) {
492
+ throw new Error ( 'revokedUser.reload() succeeded' ) ;
493
+ } )
494
+ . catch ( function ( error ) {
495
+ utils . assert (
496
+ error . code === 'auth/user-token-expired' ,
497
+ 'auth().revokeRefreshTokens(uid)' ,
498
+ 'Expected auth/user-token-expired was not thrown' ) ;
499
+ } ) ;
500
+ } )
501
+ . then ( function ( ) {
502
+ // New sign-in should succeed.
503
+ return firebase . auth ( ) . signInWithEmailAndPassword (
504
+ mockUserData . email , mockUserData . password ) ;
505
+ } )
506
+ . then ( function ( user ) {
507
+ // Get new session's ID token.
508
+ return user . getIdToken ( ) ;
509
+ } )
510
+ . then ( function ( idToken ) {
511
+ // ID token for new session should be valid even with revocation check.
512
+ return admin . auth ( ) . verifyIdToken ( idToken , true )
513
+ } )
514
+ . catch ( function ( error ) {
515
+ utils . logFailure ( 'auth().revokeRefreshTokens()' , error ) ;
516
+ } ) ;
517
+ }
452
518
453
519
return before ( )
454
520
. then ( testCreateUserWithoutUid )
455
521
. then ( testCreateUserWithUid )
456
522
. then ( testCreateDuplicateUserWithError )
523
+ . then ( testRefreshTokenRevocation )
457
524
. then ( testGetUser )
458
525
. then ( testGetUserByEmail )
459
526
. then ( testGetUserByPhoneNumber )
0 commit comments