Skip to content

Conversation

@avishalom
Copy link
Contributor

initial PR, adding comments.

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.

Mostly good. Few changes needed.

String uid = firebaseToken.getUid();
UserRecord user = userManager.getUserById(uid);
if (user.getTokensValidAfterTimestamp()
> ((long)firebaseToken.getClaims().get("iat")) * 1000) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Extract to a separate line for clarity

String uid = firebaseToken.getUid();
UserRecord user = userManager.getUserById(uid);
if (user.getTokensValidAfterTimestamp()
> ((long)firebaseToken.getClaims().get("iat")) * 1000) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Add space between (long) and firebaseToken

UserRecord user = userManager.getUserById(uid);
if (user.getTokensValidAfterTimestamp()
> ((long)firebaseToken.getClaims().get("iat")) * 1000) {
throw new FirebaseAuthException("id-token-revoked", "Firebase auth token revoked");
Copy link
Contributor

Choose a reason for hiding this comment

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

Add package-level constant for the error code

* Revokes all refresh tokens for the specified user.
*
* <p>In addition to revoking all refresh tokens for a user, all ID tokens issued
* before revocation will also be revoked at the Auth backend. Any request with an
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is incorrect. Please align with the documentation of Node.js SDK.

* associated with this FirebaseAuth instance (which by default is extracted from your service
* account)
*
* <p>If a request was made to check revoked, the issued-at property of the token (like all
Copy link
Contributor

Choose a reason for hiding this comment

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

Way too much implementation details here. Just mention something like: "If checkRevoked is true, additionally checks if the token has been revoked."

}

@Test
public void testVerifyIDToken() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

testVerifyIdToken

assertEquals("user_ver", decoded.getUid());
decoded = auth.verifyIdTokenAsync(idToken, true).get();
assertEquals("user_ver", decoded.getUid());
Thread.sleep(1100);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 1100?

fail("expecting exception");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof FirebaseAuthException);
assertEquals("id-token-revoked", ((FirebaseAuthException) e.getCause()).getErrorCode());
Copy link
Contributor

Choose a reason for hiding this comment

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

Test against the package constant when you have it.

import com.google.api.client.json.JsonFactory;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.firebase.auth.UserRecord.UpdateRequest;
Copy link
Contributor

Choose a reason for hiding this comment

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

Changes in this file seem unnecessary (just imports)?

On the other hand, why don't we have unit tests for the change in UserRecord class?


@Test
public void testVerifyIDToken() throws Exception {
String customToken = auth.createCustomTokenAsync("user_ver").get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Use "user2" or something to be consistent with other tests.

@hiranya911 hiranya911 assigned avishalom and unassigned hiranya911 Feb 2, 2018
@avishalom avishalom assigned hiranya911 and unassigned avishalom Feb 5, 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 with some nits. Please address them prior to merging.

* <p>In addition to revoking all refresh tokens for a user, all ID tokens issued
* before revocation will also be revoked at the Auth backend. Any request with an
* ID token generated before revocation will be rejected with a token expired error.
* <p>Updates the user's tokensValidAfterTimestamp to the current UTC second expressed in
Copy link
Contributor

Choose a reason for hiding this comment

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

s/second/time/

* parsed version of the token from which the UID and other claims in the token can be inspected.
* If the token is invalid, the future throws an exception indicating the failure.
*
* <p>This does not check whether a token has been revoked,
Copy link
Contributor

Choose a reason for hiding this comment

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

has been revoked. See....


/**
* Returns the timestamp beginning with which tokens are valid in seconds since the epoch.
* Returns the timestamp beginning with which tokens are valid in milliseconds since the epoch.
Copy link
Contributor

Choose a reason for hiding this comment

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

Returns a timestamp in milliseconds since epoch, truncated down to the closest second. Tokens minted before this timestamp are considered invalid.

private static void checkValidSince(long epochSeconds) {
checkArgument(epochSeconds > 0,
"validSince must be greater than 0 in seconds since the epoch: "
+ Long.toString(epochSeconds));
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary wrapping.


private static void checkValidSince(long epochSeconds) {
checkArgument(epochSeconds > 0,
"validSince must be greater than 0 in seconds since the epoch: "
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting/indentation messed up here.

// expected
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add new line at eof

UserRecord user = userManager.getUserById(uid);
long issuedAt = (long) firebaseToken.getClaims().get("iat");
if (user.getTokensValidAfterTimestamp() > issuedAt * 1000) {
throw new FirebaseAuthException(FirebaseUserManager.ID_TOKEN_REVOKED_ERROR,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong indentation?


private Task<Void> revokeRefreshTokens(String uid) {
checkNotDestroyed();
final UpdateRequest request = new UpdateRequest(uid).setValidSince(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

int currentTimeSeconds = (int) (System.currentTimeMillis() / 1000);

@hiranya911 hiranya911 assigned avishalom and unassigned hiranya911 Feb 5, 2018
@avishalom avishalom merged commit 7b410b3 into master Feb 13, 2018
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.

2 participants