Skip to content

Adding Java samples for listUsersAsync() and setCustomUserClaimsAsync() #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2017

Conversation

hiranya911
Copy link
Contributor

// [START verify_custom_claims]
// Verify the ID token first.
FirebaseToken decoded = FirebaseAuth.getInstance().verifyIdTokenAsync(idToken).get();
if (Boolean.TRUE.equals(decoded.getClaims().get("admin"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Boolean.TRUE.equals seems a bit strange. Why not just if(decoded.getClaims().get("admin"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getClaims() returns a Map<String, Object>. So when querying the map we need to deal with possible null values (if the key does not exist), and the returned value not being boolean. Boolean.TRUE.equals() provides a one-liner that deals with both cases.

.getUserByEmailAsync("[email protected]").get();
// Add incremental custom claim without overwriting the existing claims.
Map<String, Object> currentClaims = user.getCustomClaims();
if (Boolean.TRUE.equals(currentClaims.get("admin"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

Copy link
Contributor

@samtstern samtstern left a comment

Choose a reason for hiding this comment

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

LGTM but I left two comments.

@hiranya911 hiranya911 assigned hiranya911 and unassigned samtstern Nov 29, 2017
@samtstern
Copy link
Contributor

samtstern commented Nov 29, 2017 via email

@@ -155,6 +232,8 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc
getUserByEmail("[email protected]");
getUserByPhoneNumber("+11234567890");
updateUser("some-uid");
//setCustomUserClaims("some-uid");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this commented out on purpose ?

@hiranya911 hiranya911 merged commit dd74047 into master Dec 7, 2017
@hiranya911 hiranya911 deleted the hkj-auth-samples branch December 7, 2017 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants