Skip to content

Commit 95003a5

Browse files
committed
chore: resolve comments
1 parent c23059c commit 95003a5

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@
2424
public class FirebasePnvException extends Exception {
2525
private final FirebasePnvErrorCode errorCode;
2626

27+
/**
28+
* Exception that created from {@link FirebasePnvErrorCode},
29+
* {@link String} message and {@link Throwable} cause.
30+
*
31+
* @param errorCode {@link FirebasePnvErrorCode}
32+
* @param message {@link String}
33+
* @param cause {@link Throwable}
34+
*/
35+
public FirebasePnvException(
36+
FirebasePnvErrorCode errorCode,
37+
String message,
38+
Throwable cause
39+
) {
40+
super(message, cause);
41+
this.errorCode = errorCode;
42+
}
43+
2744
/**
2845
* Exception that created from {@link FirebasePnvErrorCode} and {@link String} message.
2946
*
@@ -34,8 +51,7 @@ public FirebasePnvException(
3451
FirebasePnvErrorCode errorCode,
3552
String message
3653
) {
37-
super(message);
38-
this.errorCode = errorCode;
54+
this(errorCode, message, null);
3955
}
4056

4157
public FirebasePnvErrorCode getFpnvErrorCode() {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class FirebasePnvToken {
3030
private final Map<String, Object> claims;
3131

3232
public FirebasePnvToken(Map<String, Object> claims) {
33-
// this.claims = claims != null ? Collections.unmodifiableMap(claims) : Collections.emptyMap();
3433
checkArgument(claims != null && claims.containsKey("sub"),
3534
"Claims map must at least contain sub");
3635
this.claims = ImmutableMap.copyOf(claims);
@@ -58,8 +57,14 @@ public List<String> getAudience() {
5857
Object audience = claims.get("aud");
5958
if (audience instanceof String) {
6059
return ImmutableList.of((String) audience);
60+
} else if (audience instanceof List) {
61+
// The nimbus-jose-jwt library should provide a List<String>, but we copy it
62+
// to an immutable list for safety and to prevent modification.
63+
@SuppressWarnings("unchecked")
64+
List<String> audienceList = (List<String>) audience;
65+
return ImmutableList.copyOf(audienceList);
6166
}
62-
return (List<String>) audience;
67+
return ImmutableList.of();
6368
}
6469

6570
/**

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,20 @@ public FirebasePnvToken verifyToken(String token) throws FirebasePnvException {
9595
} catch (ParseException e) {
9696
throw new FirebasePnvException(
9797
FirebasePnvErrorCode.INVALID_TOKEN,
98-
"Failed to parse JWT token: " + e.getMessage()
98+
"Failed to parse JWT token: " + e.getMessage(),
99+
e
99100
);
100101
} catch (ExpiredJWTException e) {
101-
throw new FirebasePnvException(FirebasePnvErrorCode.TOKEN_EXPIRED, "FPNV token has expired.");
102+
throw new FirebasePnvException(
103+
FirebasePnvErrorCode.TOKEN_EXPIRED,
104+
"FPNV token has expired.",
105+
e
106+
);
102107
} catch (BadJOSEException | JOSEException e) {
103108
throw new FirebasePnvException(FirebasePnvErrorCode.SERVICE_ERROR,
104109
"Check your project: " + projectId + ". "
105-
+ e.getMessage()
110+
+ e.getMessage(),
111+
e
106112
);
107113
}
108114
}
@@ -140,7 +146,7 @@ private void verifyClaims(JWTClaimsSet claims) throws FirebasePnvException {
140146

141147
if (Strings.isNullOrEmpty(issuer)) {
142148
throw new FirebasePnvException(FirebasePnvErrorCode.INVALID_ARGUMENT,
143-
"Invalid issuer. Expected: " + issuer);
149+
"FPNV token has no 'iss' (issuer) claim.");
144150
}
145151

146152
// Verify Audience

0 commit comments

Comments
 (0)