8000 [OID4VCI]: Add a unique notification_id generation to OID4VCIssuerEndpoint used in CredentialResponse. by Ogenbertrand · Pull Request #40229 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[OID4VCI]: Add a unique notification_id generation to OID4VCIssuerEndpoint used in CredentialResponse. #40229

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 7 commits 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 @@ -203,6 +203,15 @@ private Map<String, CredentialBuilder> loadCredentialBuilders(KeycloakSession ke
.collect(Collectors.toMap(CredentialBuilder::getSupportedFormat, component -> component));
}

/**
* Generates a unique notification ID for use in CredentialResponse.
*
* @return a unique string identifier
*/
private String generateNotificationId() {
return SecretGenerator.getInstance().randomString();
}

/**
* the OpenId4VCI nonce-endpoint
*
Expand Down Expand Up @@ -408,7 +417,9 @@ public Response requestCredential(

Object theCredential = getCredential(authResult, supportedCredentialConfiguration, credentialRequestVO);
if (SUPPORTED_FORMATS.contains(requestedFormat)) {
responseVO.addCredential(theCredential);
responseVO
.addCredential(theCredential)
.setNotificationId(generateNotificationId());
} else {
throw new BadRequestException(getErrorResponse(ErrorType.UNSUPPORTED_CREDENTIAL_TYPE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ public CredentialResponse setCredentials(List<Credential> credentials) {
return this;
}

public void addCredential(Object credential) {
public CredentialResponse addCredential(Object credential) {
if (this.credentials == null) {
this.credentials = new ArrayList<>();
}
this.credentials.add(new Credential().setCredential(credential));
return this;
}

public String getTransactionId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -539,4 +540,33 @@ public void testCredentialIssuanceWithRealmScopeMissing() throws Exception {
}
});
}

@Test
public void testRequestCredentialWithNotificationId() {
String token = getBearerToken(oauth);
testingClient.server(TEST_REALM_NAME).run((session) -> {
AppAuthManager.BearerTokenAuthenticator authenticator = new AppAuthManager.BearerTokenAuthenticator(session);
authenticator.setTokenString(token);
OID4VCIssuerEndpoint issuerEndpoint = prepareIssuerEndpoint(session, authenticator);

CredentialRequest credentialRequest = new CredentialRequest()
.setFormat(Format.JWT_VC)
.setCredentialIdentifier("test-credential");

// First credential request
Response response1 = issuerEndpoint.requestCredential(credentialRequest);
assertEquals("The credential request should be successful.", 200, response1.getStatus());
CredentialResponse credentialResponse1 = JsonSerialization.mapper.convertValue(response1.getEntity(), CredentialResponse.class);
assertNotNull("Credential response should not be null", credentialResponse1);
assertNotNull("Credential should be present", credentialResponse1.getCredentials());
assertNotNull("Notification ID should be present", credentialResponse1.getNotificationId());
assertFalse("Notification ID should not be empty", credentialResponse1.getNotificationId().isEmpty());

// Second credential request
Response response2 = issuerEndpoint.requestCredential(credentialRequest);
assertEquals("The second credential request should be successful.", 200, response2.getStatus());
CredentialResponse credentialResponse2 = JsonSerialization.mapper.convertValue(response2.getEntity(), CredentialResponse.class);
assertNotEquals("Notification IDs should be unique", credentialResponse1.getNotificationId(), credentialResponse2.getNotificationId());
});
}
}
Loading
0