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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

### Fixes

- Fixed creating JWTs using MongoDB if a key already exists

### Breaking changes

- Using an internal `SemVer` class to handle version numbers. This will make handling CDI version ranges easier.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/supertokens/signingkeys/JWTSigningKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ public JWTSigningKeyInfo getOrCreateAndGetKeyForAlgorithm(SupportedAlgorithms al
// Retry with a new key id
}
}

return keyInfo;
}

return keyInfo;
}

throw new QuitProgramException("Unsupported storage type detected");
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/io/supertokens/test/jwt/JWTCreateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ public void testNormalFunctioningOfCreateToken() throws Exception {
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}

/**
* Call JWTSigningFunctions.createJWTToken with valid params twice and ensure that it does not throw any errors
*/
@Test
public void testCreateTokenWithAlreadyExistingKey() throws Exception {
String[] args = { "../" };
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

String algorithm = "RS256";
JsonObject payload = new JsonObject();
payload.addProperty("customClaim", "customValue");
String jwksDomain = "http://localhost";
long validity = 3600;

JWTSigningFunctions.createJWTToken(process.getProcess(), algorithm, payload, jwksDomain, validity, false);
JWTSigningFunctions.createJWTToken(process.getProcess(), algorithm, payload, jwksDomain, validity, false);

process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}

/**
* Call JWTSigningFunctions.createJWTToken with valid params and long validity and ensure that it does not throw any
* errors
Expand Down