Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bucchi
Copy link
Contributor

@bucchi bucchi commented May 20, 2024

#17616 (comment)
As discussion above, commit test code for "Step1:without scope parameter mode" .

closes #29724

Step1 for without scope parameter mode

Fixes keycloak#23628

Signed-off-by: Yutaka Obuchi <[email protected]>
@tnorimat
Copy link
Contributor

@bucchi I created a sub issue for the main issue.

Could you modify your commit log from

Fixes #23628

to

Closes #29724

?

Copy link
Contributor

@tnorimat tnorimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bucchi Thank you. I reviewed the PR and I added some review comments. Could you check them ?

Also, when you finally squash commits after the PR is approved, could you fix the PR's squashed commit message as I mentioned in the previous comment of the PR?

Response discoveryResponse = oid4vciDiscoveryTarget.request().get();
CredentialIssuer oid4vciIssuerConfig = JsonSerialization.readValue(discoveryResponse.readEntity(String.class), CredentialIssuer.class);

assertEquals(200, discoveryResponse.getStatus());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it might be good if this assertion be just after L458 (line 458).

CredentialIssuer oid4vciIssuerConfig = JsonSerialization.readValue(discoveryResponse.readEntity(String.class), CredentialIssuer.class);

assertEquals(200, discoveryResponse.getStatus());
assertEquals("https://localhost:8543/auth/realms/test", oid4vciIssuerConfig.getCredentialIssuer());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, could you avoid hard-coded https://localhost:8543/auth/realms/test ?


assertEquals(200, discoveryResponse.getStatus());
assertEquals("https://localhost:8543/auth/realms/test", oid4vciIssuerConfig.getCredentialIssuer());
assertEquals("https://localhost:8543/auth/realms/test/protocol/oid4vc/credential", oid4vciIssuerConfig.getCredentialEndpoint());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, could you avoid hard-coded https://localhost:8543/auth/realms/test/protocol/oid4vc/credential ?

request.setFormat(oid4vciIssuerConfig.getCredentialsSupported().get("test-credential").getFormat());
request.setCredentialIdentifier(oid4vciIssuerConfig.getCredentialsSupported().get("test-credential").getId());

assertEquals("jwt_vc", oid4vciIssuerConfig.getCredentialsSupported().get("test-credential").getFormat().toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"jwt_vc" can be Format.JWT_VC.toString() .

Response response = credentialTarget.request().header(HttpHeaders.AUTHORIZATION, "bearer " + token).post(Entity.json(request));
CredentialResponse credentialResponse = JsonSerialization.readValue(response.readEntity(String.class),CredentialResponse.class);

assertEquals(200, response.getStatus());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it might be good if this assertion be just after L478 (line 478).

assertEquals("https://localhost:8543/auth/realms/test/protocol/oid4vc/credential", oid4vciIssuerConfig.getCredentialEndpoint());

// 4. With the access token, get the credential
Client clientForCredentialRequest = AdminClientUtil.createResteasyClient();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as L454 (line 454).

String token = getBearerToken(oauth.openid(false).scope(null));

// 3. Get the credential configuration id from issuer metadata at .wellKnown
Client client = AdminClientUtil.createResteasyClient();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use try-finally clause for this Client clientForCredentialRequest.
For example, see

@Test
public void testHttpDiscovery() {
Client client = AdminClientUtil.createResteasyClient();
try {
OIDCConfigurationRepresentation oidcConfig = getOIDCDiscoveryRepresentation(client, "http://localhost:8180/auth");
Assert.assertNotNull(oidcConfig.getJwksUri());
// Token Revocation
Assert.assertNotNull(oidcConfig.getRevocationEndpoint());
Assert.assertNotNull(oidcConfig.getRevocationEndpointAuthMethodsSupported());
Assert.assertNotNull(oidcConfig.getRevocationEndpointAuthSigningAlgValuesSupported());
} finally {
client.close();
}
}

Or, maybe, it can be re-written as follows:

        Response discoveryResponse;
        CredentialIssuer oid4vciIssuerConfig;
        try (Client client = AdminClientUtil.createResteasyClient()) {
            UriBuilder builder = UriBuilder.fromUri(OAuthClient.AUTH_SERVER_ROOT);
            URI oid4vciDiscoveryUri = RealmsResource.wellKnownProviderUrl(builder).build("test", OID4VCIssuerWellKnownProviderFactory.PROVIDER_ID);
            WebTarget oid4vciDiscoveryTarget = client.target(oid4vciDiscoveryUri);
            discoveryResponse = oid4vciDiscoveryTarget.request().get();
            oid4vciIssuerConfig = JsonSerialization.readValue(discoveryResponse.readEntity(String.class), CredentialIssuer.class);
        }

assertEquals("jwt_vc", oid4vciIssuerConfig.getCredentialsSupported().get("test-credential").getFormat().toString());
assertEquals("test-credential", oid4vciIssuerConfig.getCredentialsSupported().get("test-credential").getId());

Response response = credentialTarget.request().header(HttpHeaders.AUTHORIZATION, "bearer " + token).post(Entity.json(request));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as L454 (line 454).

Copy link
Contributor

@francis-pouatcha francis-pouatcha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bucchi all my review comment match those of @tnorimat . I sent a pull request Hitachi#707 to address those issues.

Copy link
Contributor

@tnorimat tnorimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LTGM.

@tnorimat
Copy link
Contributor

@mposolda I approved the PR. Could you check it?

@tnorimat
Copy link
Contributor

The PR closes #29724

Copy link
Contributor

@mposolda mposolda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bucchi @tnorimat @francis-pouatcha Thanks for the fix and reviews!

Copy link
Contributor

@mposolda mposolda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bucchi @tnorimat @francis-pouatcha Thanks for the PR and reviews!

@mposolda mposolda merged commit 68d9dce into keycloak:main May 28, 2024
@tnorimat
Copy link
Contributor

@mposolda Thank you!

@tnorimat tnorimat deleted the 26328-OID4VCIAuthZCodeFlow-without-scope branch May 21, 2025 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VC issuance in Authz Code flow without considering “scope” parameter

4 participants