Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/com/uid2/shared/attest/JwtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public JwtValidationResponse validateJwt(String jwt, String audience, String iss
throw new ValidationException(Optional.of("Unable to get public keys. Validation can not continue"));
}

Exception lastException = null;

for (PublicKey key : this.publicKeys) {
var tokenVerifier = TokenVerifier.newBuilder()
.setPublicKey(key)
Expand All @@ -83,10 +85,14 @@ public JwtValidationResponse validateJwt(String jwt, String audience, String iss
// return the first verified response
return response;
} catch (Exception e) {
LOGGER.error("Error validating JWT", e);
throw new ValidationException(Optional.ofNullable(e.getMessage()));
lastException = e;
}
}

if (!response.getIsValid()) {
throw new ValidationException(Optional.ofNullable(lastException.getMessage()), lastException);
}

return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public void handle(RoutingContext rc) {
}
}

if (!isJwtValid && this.enforceJwt) {
if (success && !isJwtValid && this.enforceJwt) {
LOGGER.info("JWT validation has failed.");
success = false;
} else if (!isJwtValid && !this.enforceJwt) {
} else if (success && !isJwtValid && !this.enforceJwt) {
LOGGER.info("JWT validation has failed, but JWTs are not being enforced.");
}

Expand Down
Loading