55import com .google .firebase .FirebaseOptions ;
66import com .google .firebase .auth .ExportedUserRecord ;
77import com .google .firebase .auth .FirebaseAuth ;
8+ import com .google .firebase .auth .FirebaseAuthException ;
89import com .google .firebase .auth .FirebaseToken ;
910import com .google .firebase .auth .ListUsersPage ;
1011import com .google .firebase .auth .UserRecord ;
1112import com .google .firebase .auth .UserRecord .CreateRequest ;
1213import com .google .firebase .auth .UserRecord .UpdateRequest ;
14+ import com .google .firebase .database .*;
1315import java .io .FileInputStream ;
1416import java .io .IOException ;
1517import java .util .HashMap ;
@@ -216,13 +218,14 @@ public static void verifyIdTokenCheckRevoked(String idToken) throws InterruptedE
216218 FirebaseToken decodedToken = FirebaseAuth .getInstance ().verifyIdTokenAsync (idToken , checkRevoked ).get ();
217219 // Token is valid and not revoked.
218220 String uid = decodedToken .getUid ();
219- }
220- catch (FirebaseAuthException e ) {
221- if ("id-token-revoked" .equals (e .getErrorCode ())) {
222- // Token is valid but has been revoked.
223- // When this occurs, inform the user to reauthenticate or signOut() the user.
224- } else {
225- // Token is invalid.
221+ } catch (ExecutionException e ) {
222+ if (e .getCause () instanceof FirebaseAuthException ) {
223+ FirebaseAuthException authError = (FirebaseAuthException ) e .getCause ();
224+ if (authError .getErrorCode ().equals ("id-token-revoked" )) {
225+ // Token has been revoked. Inform the user to reauthenticate or signOut() the user.
226+ } else {
227+ // Token is invalid.
228+ }
226229 }
227230 }
228231 // [END verify_id_token_check_revoked]
@@ -231,7 +234,7 @@ public static void verifyIdTokenCheckRevoked(String idToken) throws InterruptedE
231234 public static void revokeIdTokens (String idToken ) throws InterruptedException , ExecutionException {
232235 String uid ="someUid" ;
233236 // [START revoke_tokens]
234- FirebaseToken decodedToken = FirebaseAuth .getInstance ().revokeRefreshTokens (uid ).get ();
237+ FirebaseAuth .getInstance ().revokeRefreshTokensAsync (uid ).get ();
235238 UserRecord user = FirebaseAuth .getInstance ().getUserAsync (uid ).get ();
236239 // Convert to seconds as the auth_time in the token claims is in seconds too.
237240 long revocationSecond = user .getTokensValidAfterTimestamp () / 1000 ;
@@ -240,7 +243,9 @@ public static void revokeIdTokens(String idToken) throws InterruptedException, E
240243
241244 // [START save_revocation_in_db]
242245 DatabaseReference ref = FirebaseDatabase .getInstance ().getReference ("metadata/" + uid );
243- ref .setValueAsync (MapBuilder .of ("revokeTime" , revocationSecond )).get ();
246+ Map <String , Object > userData = new HashMap <>();
247+ userData .put ("revokeTime" , revocationSecond );
248+ ref .setValueAsync (userData ).get ();
244249 // [END save_revocation_in_db]
245250
246251 }
0 commit comments