Skip to content

Revoke tokens and verify check revoked snippets #21

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 14 commits into from
Feb 13, 2018
Merged

Conversation

avishalom
Copy link
Contributor

No description provided.

.project Outdated
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these .project files should be excluded

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, they snuck right in there in the last commit,
removing

@samtstern
Copy link
Contributor

@avishalom Travis is saying that things don't compile. Are these snippets for unreleased code?

@avishalom
Copy link
Contributor Author

Yes,
it is unreleased. I'm not sure how to set up the build to pull the newer branch, as it is it is pulling version 5.6.0 (which is 2 behind)

@samtstern
Copy link
Contributor

@avishalom yeah there's not much we can do since the Java Admin SDK does not publish snapshot builds anywhere. We'll just have to hold this PR unmerged until the SDK is released and we can update your branch to the public version (I guess 5.9.0 ?)

@avishalom
Copy link
Contributor Author

Ok, we can do it in steps.
do you know how firebase/snippets-java#2 is green? it contains FCM code that doesn't exist in 5.8.0 ?

@samtstern
Copy link
Contributor

@avishalom that pull request was sent before I enabled Travis on the repository (I only added Travis this week) so I guess it never built at all.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

A few nits to address.

try {
// Verify the ID token while checking if the token is revoked by passing checkRevoked
// as true.
FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdTokenAsync(idToken, true).get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this as follows for clarity:

boolean checkRevoked = true;
FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdTokenAsync(idToken, checkRevoked).get();

String uid = decodedToken.getUid();
}
catch (FirebaseAuthException e) {
if (FirebaseUserManager.ID_TOKEN_REVOKED_ERROR == e.getErrorCode()) {
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 really visible in the public API?

System.out.println("Decoded ID token from user: " + uid);
}

public static void revokeIdTokens(String idToken) throws InterruptedException, ExecutionException {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like an equivalent version of a Functions sample we have in docs. If so, it might not be useful at this point.

// Save the refresh token revocation timestamp. This is needed to track ID token
// revocation via Firebase rules.
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("metadata/" + uid);
ref.setValueAsync(MapBuilder.of("revokeTime", revocationSecond));
Copy link
Contributor

Choose a reason for hiding this comment

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

Add .get() at the end to block?

@hiranya911 hiranya911 assigned avishalom and unassigned hiranya911 Feb 9, 2018
@avishalom avishalom removed their assignment Feb 11, 2018
Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

Almost there. Few corrections needed.

String uid = decodedToken.getUid();
System.out.println("Decoded ID token not revoked from user: " + uid);
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a comment // Token is valid is sufficient here

}
catch (FirebaseAuthException e) {
if (FirebaseUserManager.ID_TOKEN_REVOKED_ERROR == e.getErrorCode()) {
if ("id-token-revoked" == e.getErrorCode()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

.equals()

@@ -234,13 +235,14 @@ public static void revokeIdTokens(String idToken) throws InterruptedException, E
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;
System.err.println("Tokens revoked at: ", revocationSecond);
Copy link
Contributor

Choose a reason for hiding this comment

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

+ revocationSecond

@hiranya911 hiranya911 assigned avishalom and unassigned hiranya911 Feb 12, 2018
@avishalom avishalom assigned hiranya911 and unassigned avishalom Feb 12, 2018
Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@hiranya911 hiranya911 assigned avishalom and unassigned hiranya911 Feb 12, 2018
@avishalom avishalom merged commit 2f5080a into master Feb 13, 2018
@avishalom avishalom deleted the revoke_tokens branch February 13, 2018 02:02
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