Skip to content

Commit 18f5ecb

Browse files
committed
chore: resolve comments
1 parent d9df9a9 commit 18f5ecb

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

src/main/java/com/google/firebase/fpnv/FirebasePnvToken.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public class FirebasePnvToken {
3131
private final Map<String, Object> claims;
3232

3333
/**
34-
* Create an instance of {@link FirebasePnvToken} from {@link JWTClaimsSet} claims.
34+
* Create an instance of {@link FirebasePnvToken} from a map of JWT claims.
3535
*
36-
* @param claims Map claims.
36+
* @param claims A map of JWT claims.
3737
*/
3838
public FirebasePnvToken(Map<String, Object> claims) {
3939
checkArgument(claims != null && claims.containsKey("sub"),
@@ -91,6 +91,6 @@ public long getIssuedAt() {
9191
* Returns the entire map of claims.
9292
*/
9393
public Map<String, Object> getClaims() {
94-
return claims;
94+
return ImmutableMap.copyOf(claims);
9595
}
9696
}

src/main/java/com/google/firebase/fpnv/internal/FirebasePnvTokenVerifier.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,12 @@ public FirebasePnvToken verifyToken(String token) throws FirebasePnvException {
7777
checkArgument(!Strings.isNullOrEmpty(token), "FPNV token must not be null or empty");
7878

7979
try {
80-
// Parse the token first to inspect header
8180
SignedJWT signedJwt = SignedJWT.parse(token);
82-
83-
// Explicitly verify the header (alg & kid)
8481
verifyHeader(signedJwt.getHeader());
8582

86-
// Verify Signature and Structure
8783
JWTClaimsSet claims = jwtProcessor.process(signedJwt, null);
88-
89-
// Verify Claims (Issuer, Audience, Expiration)
9084
verifyClaims(claims);
9185

92-
// Construct Token Object
9386
return new FirebasePnvToken(claims.getClaims());
9487
} catch (ParseException e) {
9588
throw new FirebasePnvException(
@@ -122,7 +115,7 @@ public FirebasePnvToken verifyToken(String token) throws FirebasePnvException {
122115

123116
private void verifyHeader(JWSHeader header) throws FirebasePnvException {
124117
// Check Algorithm (alg)
125-
if (!JWSAlgorithm.ES256.equals(header.getAlgorithm())) {
118+
if (!header.getAlgorithm().equals(JWSAlgorithm.ES256)) {
126119
throw new FirebasePnvException(
127120
FirebasePnvErrorCode.INVALID_ARGUMENT,
128121
"FPNV has incorrect 'algorithm'. Expected " + JWSAlgorithm.ES256.getName()
@@ -135,8 +128,8 @@ private void verifyHeader(JWSHeader header) throws FirebasePnvException {
135128
"FPNV has no 'kid' claim."
136129
);
137130
}
138-
// Check Typ (typ)
139-
if (Objects.isNull(header.getType()) || !HEADER_TYP.equals(header.getType().getType())) {
131+
// Check Type (typ)
132+
if (Objects.isNull(header.getType()) || !header.getType().toString().equals(HEADER_TYP)) {
140133
throw new FirebasePnvException(
141134
FirebasePnvErrorCode.INVALID_ARGUMENT,
142135
"FPNV has incorrect 'typ'. Expected " + HEADER_TYP

0 commit comments

Comments
 (0)