Skip to content

Commit 6f480cd

Browse files
committed
feat: make a nonce in a token response optional
1 parent 46765d8 commit 6f480cd

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/main/java/org/hyperledger/identus/keycloak/IdentusClient.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ public class IdentusClient {
1717

1818
private static final Logger logger = Logger.getLogger(IdentusClient.class);
1919

20-
private final String identusUrl;
20+
private final String identusUrl = System.getenv("IDENTUS_URL");
2121

2222
private final Supplier<CloseableHttpClient> httpClient = IdentusClient::newCloseableHttpClient;
2323

2424
public IdentusClient() {
25-
this.identusUrl = System.getenv("IDENTUS_URL");
2625
if (this.identusUrl == null) {
27-
throw new NullPointerException("The URL of identus client is null. The IDENTUS_URL environment variable is not set.");
26+
logger.warn("The URL of the Identus Cloud Agent client is null. The IDENTUS_URL environment variable is not set. The token response will not contain a nonce.");
2827
}
2928
}
3029

30+
public Boolean isIdentusUrlSet() {
31+
return this.identusUrl != null;
32+
}
33+
3134
public static CloseableHttpClient newCloseableHttpClient() {
3235
return HttpClientBuilder.create().build();
3336
}

src/main/java/org/hyperledger/identus/keycloak/OID4VCITokenEndpoint.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public Response createTokenResponse(UserModel user, UserSessionModel userSession
3636
Response originalResponse = super.createTokenResponse(user, userSession, clientSessionCtx, scopeParam, true, clientPolicyContextGenerator);
3737
AccessTokenResponse responseEntity = (AccessTokenResponse) originalResponse.getEntity();
3838

39-
String token = responseEntity.getToken();
40-
NonceResponse nonceResponse = identusClient.getNonce(token, issuerState);
41-
responseEntity.setOtherClaims(OID4VCIConstants.C_NONCE, nonceResponse.getNonce());
42-
responseEntity.setOtherClaims(OID4VCIConstants.C_NONCE_EXPIRE, nonceResponse.getNonceExpiresIn());
39+
if (identusClient.isIdentusUrlSet()) {
40+
String token = responseEntity.getToken();
41+
NonceResponse nonceResponse = identusClient.getNonce(token, issuerState);
42+
responseEntity.setOtherClaims(OID4VCIConstants.C_NONCE, nonceResponse.getNonce());
43+
responseEntity.setOtherClaims(OID4VCIConstants.C_NONCE_EXPIRE, nonceResponse.getNonceExpiresIn());
44+
}
4345
return Response.fromResponse(originalResponse)
4446
.entity(responseEntity)
4547
.build();

0 commit comments

Comments
 (0)