Skip to content

UID2-5673 Add JTI to JWTTokenProvider #312

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.time.Instant;
import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.security.MessageDigest;

Expand Down Expand Up @@ -80,6 +81,7 @@ private String getJWTToken(String issuer, String audience, String operatorKey, S
claims.put("enclaveId", enclaveId);
claims.put("enclaveType", enclaveType);
claims.put("operatorVersion", operatorVersion);
claims.put("jti", UUID.randomUUID().toString());

LOGGER.debug(String.format("Creating token with: Issuer: %s, Audience: %s, Roles: %s, SiteId: %s, EnclaveId: %s, EnclaveType: %s, OperatorVersion: %s", audience, issuer, roleString, siteId, enclaveId, enclaveType, operatorVersion));
return this.jwtTokenProvider.getJWT(expiresAt, this.clock.instant(), claims);
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/uid2/core/service/JWTTokenProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Base64;
import java.util.HashMap;
import java.util.Optional;
import java.util.UUID;

import static com.uid2.shared.Utils.readToEndAsString;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -53,8 +54,10 @@ void getJwtReturnsValidToken() throws JWTTokenProvider.JwtSigningException {
headers.put("c", "d");

HashMap<String, String> content = new HashMap<>();
String jti = UUID.randomUUID().toString();
content.put("sub", "subject");
content.put("iss", "issuer");
content.put("jti", jti);

var builder = getBuilder(true, "TestSignature");
JWTTokenProvider provider = new JWTTokenProvider(config, () -> builder);
Expand All @@ -74,6 +77,7 @@ void getJwtReturnsValidToken() throws JWTTokenProvider.JwtSigningException {
contentJson.put("iat", i.getEpochSecond());
contentJson.put("sub", "subject");
contentJson.put("iss", "issuer");
contentJson.put("jti", jti);

assertJWT(defaultHeaders.encode(), contentJson.encode(), expectedSig, result);
assertEquals("1234", this.capturedSignRequest.getValue().keyId());
Expand Down