5
5
import com .google .firebase .FirebaseOptions ;
6
6
import com .google .firebase .auth .ExportedUserRecord ;
7
7
import com .google .firebase .auth .FirebaseAuth ;
8
+ import com .google .firebase .auth .FirebaseAuthException ;
8
9
import com .google .firebase .auth .FirebaseToken ;
9
10
import com .google .firebase .auth .ListUsersPage ;
10
11
import com .google .firebase .auth .UserRecord ;
11
12
import com .google .firebase .auth .UserRecord .CreateRequest ;
12
13
import com .google .firebase .auth .UserRecord .UpdateRequest ;
14
+ import com .google .firebase .database .*;
13
15
import java .io .FileInputStream ;
14
16
import java .io .IOException ;
15
17
import java .util .HashMap ;
@@ -216,13 +218,14 @@ public static void verifyIdTokenCheckRevoked(String idToken) throws InterruptedE
216
218
FirebaseToken decodedToken = FirebaseAuth .getInstance ().verifyIdTokenAsync (idToken , checkRevoked ).get ();
217
219
// Token is valid and not revoked.
218
220
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
+ }
226
229
}
227
230
}
228
231
// [END verify_id_token_check_revoked]
@@ -231,7 +234,7 @@ public static void verifyIdTokenCheckRevoked(String idToken) throws InterruptedE
231
234
public static void revokeIdTokens (String idToken ) throws InterruptedException , ExecutionException {
232
235
String uid ="someUid" ;
233
236
// [START revoke_tokens]
234
- FirebaseToken decodedToken = FirebaseAuth .getInstance ().revokeRefreshTokens (uid ).get ();
237
+ FirebaseAuth .getInstance ().revokeRefreshTokensAsync (uid ).get ();
235
238
UserRecord user = FirebaseAuth .getInstance ().getUserAsync (uid ).get ();
236
239
// Convert to seconds as the auth_time in the token claims is in seconds too.
237
240
long revocationSecond = user .getTokensValidAfterTimestamp () / 1000 ;
@@ -240,7 +243,9 @@ public static void revokeIdTokens(String idToken) throws InterruptedException, E
240
243
241
244
// [START save_revocation_in_db]
242
245
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 ();
244
249
// [END save_revocation_in_db]
245
250
246
251
}
0 commit comments