@@ -209,8 +209,9 @@ public static void verifyIdToken(String idToken) throws InterruptedException, Ex
209209
210210 public static void verifyIdTokenCheckRevoked (String idToken ) throws InterruptedException , ExecutionException {
211211 // [START verify_id_token_check_revoked]
212- // Note the second parameter, checkRevoked set to true.
213212 try {
213+ // Verify the ID token while checking if the token is revoked by passing checkRevoked
214+ // as true.
214215 FirebaseToken decodedToken = FirebaseAuth .getInstance ().verifyIdTokenAsync (idToken , true ).get ();
215216 String uid = decodedToken .getUid ();
216217 }
@@ -226,15 +227,17 @@ public static void verifyIdTokenCheckRevoked(String idToken) throws InterruptedE
226227 System .out .println ("Decoded ID token from user: " + uid );
227228 }
228229
229- public static void revokeIdTokens (String idToken ) throws InterruptedException , ExecutionException {
230+ public static void revokeIdTokens (String idToken ) {
230231 String uid ="someUid" ;
231232 // [START revoke_tokens]
232233 FirebaseToken decodedToken = FirebaseAuth .getInstance ().revokeRefreshTokens (uid ).get ();
233234 UserRecord user = FirebaseAuth .getInstance ().getUserAsync (uid ).get ();
235+ // Convert to seconds as the auth_time in the token claims is in seconds too.
234236 long revocationSecond = user .getTokensValidAfterTimestamp () / 1000 ;
235237
236- final FirebaseDatabase database = FirebaseDatabase .getInstance ();
237- DatabaseReference ref = database .getReference ("metadata/" + uid );
238+ // Save the refresh token revocation timestamp. This is needed to track ID token
239+ // revocation via Firebase rules.
240+ DatabaseReference ref = FirebaseDatabase .getInstance ().getReference ("metadata/" + uid );
238241 ref .setValueAsync (MapBuilder .of ("revokeTime" , revocationSecond ));
239242 // [END revoke_tokens]
240243 System .out .println ("Decoded ID token from user: " + uid );
0 commit comments