Skip to content
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.google.firebase.quickstart;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.collect.ImmutableMap;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.auth.ExportedUserRecord;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.auth.FirebaseToken;
import com.google.firebase.auth.ListUsersPage;
import com.google.firebase.auth.UserRecord;
import com.google.firebase.auth.UserRecord.CreateRequest;
import com.google.firebase.auth.UserRecord.UpdateRequest;
import com.google.firebase.database.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -216,13 +219,13 @@ public static void verifyIdTokenCheckRevoked(String idToken) throws InterruptedE
FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdTokenAsync(idToken, checkRevoked).get();
// Token is valid and not revoked.
String uid = decodedToken.getUid();
}
catch (FirebaseAuthException e) {
if ("id-token-revoked".equals(e.getErrorCode())) {
// Token is valid but has been revoked.
// When this occurs, inform the user to reauthenticate or signOut() the user.
} else {
// Token is invalid.
} catch (ExecutionException e) {
if (e.getCause() instanceof FirebaseAuthException) {
if ( ((FirebaseAuthException) e.getCause()).getErrorCode().equals("id-token-revoked")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break into a couple of lines:

FirebaseAuthException authError = ...;

// Token has been revoked. Inform the user to reauthenticate or signOut() the user.
} else {
// Token is invalid.
}
}
}
// [END verify_id_token_check_revoked]
Expand All @@ -231,7 +234,7 @@ public static void verifyIdTokenCheckRevoked(String idToken) throws InterruptedE
public static void revokeIdTokens(String idToken) throws InterruptedException, ExecutionException {
String uid="someUid";
// [START revoke_tokens]
FirebaseToken decodedToken = FirebaseAuth.getInstance().revokeRefreshTokens(uid).get();
FirebaseAuth.getInstance().revokeRefreshTokensAsync(uid).get();
UserRecord user = FirebaseAuth.getInstance().getUserAsync(uid).get();
// Convert to seconds as the auth_time in the token claims is in seconds too.
long revocationSecond = user.getTokensValidAfterTimestamp() / 1000;
Expand All @@ -240,7 +243,7 @@ public static void revokeIdTokens(String idToken) throws InterruptedException, E

// [START save_revocation_in_db]
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("metadata/" + uid);
ref.setValueAsync(MapBuilder.of("revokeTime", revocationSecond)).get();
ref.setValueAsync(ImmutableMap.<String, Object>of("revokeTime", revocationSecond)).get();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use HashMap here. ImmutableMap is a guava type and I don't think we want it to appear in snippets.

// [END save_revocation_in_db]

}
Expand Down