Skip to content

Supporting OID4VCI AuthZCode flow: - #29685

Merged
mposolda merged 2 commits into
keycloak:mainfrom
Hitachi:26328-OID4VCIAuthZCodeFlow-without-scope
May 28, 2024
Merged

Supporting OID4VCI AuthZCode flow:#29685
mposolda merged 2 commits into
keycloak:mainfrom
Hitachi:26328-OID4VCIAuthZCodeFlow-without-scope

Conversation

@bucchi

@bucchi bucchi commented May 20, 2024

Copy link
Copy Markdown
Contributor

#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 <yutaka.obuchi.sd@hitachi.com>
@tnorimat

Copy link
Copy Markdown
Contributor

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

Could you modify your commit log from

Fixes #23628

to

Closes #29724

?

@tnorimat tnorimat left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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).

@francis-pouatcha francis-pouatcha left a comment

Copy link
Copy Markdown
Contributor

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.

…view-2067746577

Signed-off-by: Francis Pouatcha <francis.pouatcha@adorsys.com>

@tnorimat tnorimat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LTGM.

@tnorimat

Copy link
Copy Markdown
Contributor

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

@tnorimat

Copy link
Copy Markdown
Contributor

The PR closes #29724

@mposolda mposolda left a comment

Copy link
Copy Markdown
Contributor

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!

@mposolda mposolda left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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