8000 [OID4VCI] Initial public client for credential issuance by tdiesler · Pull Request #45855 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

[OID4VCI] Initial public client for credential issuance - #45855

Merged
mposolda merged 3 commits into
keycloak:mainfrom
tdiesler:ghi45851
Apr 1, 2026
Merged

mposolda merged 3 commits into
keycloak:mainfrom
tdiesler:ghi45851

Conversation

@tdiesler
@tdiesler tdiesler commented Jan 29, 2026 •
Copy link
Copy Markdown
Contributor

closes #47280

The PR ...

  • adds a public client test-app-pub to testrealm.json
  • adds a comprehensive test using the new OAuthClient APIs (i.e. OID4VCPublicClientTest)
  • adds support for error page/redirect to the AuthorizationRequest
  • removes dependency on OID4VCIssuerEndpointTest.getCredentialOfferUriUrl()

@tdiesler
tdiesler requested review from a team as code owners January 29, 2026 10:40
@tdiesler
tdiesler marked this pull request as draft January 29, 2026 14:55
@tdiesler tdiesler changed the title [OID4CVI] No test coverage for public clients [OID4CVI] Review and fix issuance on public clients Jan 30, 2026
@tdiesler
tdiesler force-pushed the ghi45851 branch 14 times, most recently from 200c89c to b3986fc Compare February 4, 2026 17:24
@tdiesler
tdiesler marked this pull request as draft February 25, 2026 07:55
@tdiesler
tdiesler force-pushed the ghi45851 branch 3 times, most recently from 28edf37 to ecce3a0 Compare February 26, 2026 11:33
@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.model.infinispan.EmbeddedInfinispanSplitBrainTest#testLocalCacheClearedOnMergeEvent

Keycloak CI - Store Model Tests

java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.keycloak.testsuite.model.infinispan.EmbeddedInfinispanSplitBrainTest.awaitLatch(EmbeddedInfinispanSplitBrainTest.java:112)
...
java.lang.AssertionError
	at org.keycloak.testsuite.model.infinispan.PartitionManager$Partition.assertPartitionFormed(PartitionManager.java:126)
	at org.keycloak.testsuite.model.infinispan.PartitionManager$Partition.partition(PartitionManager.java:111)
	at org.keycloak.testsuite.model.infinispan.PartitionManager.splitCluster(PartitionManager.java:67)
	at org.keycloak.testsuite.model.infinispan.EmbeddedInfinispanSplitBrainTest.lambda$testLocalCacheClearedOnMergeEvent$0(EmbeddedInfinispanSplitBrainTest.java:87)
...

Report flaky test

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@Ogenbertrand Ogenbertrand 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.

Thanks for this PR @tdiesler !
I added a few comment, could you check them.

@Ogenbertrand Ogenbertrand 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.

I confirm that my request were all resolved.
Thanks @tdiesler for considering them, PR LGTM.

@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.

@tdiesler Thanks for this PR! Added few comments inline

Comment thread tests/utils-shared/pom.xml Outdated
@@ -31,11 +31,20 @@
<packaging>jar</packaging>
<description>Keycloak Testsuite Utilities shared between legacy and new testsuites</description>

<properties>
<selenium.version>4.28.1</selenium.version>
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.

Is it needed to update selenium in this PR?

Selenium update is good, but should be rather done in separate PR (rather than inside the OID4VC specific PR) and should be likely after Keycloak 26.6 to avoid any unexpected issues with testsuite stability closely before release.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

selenium isn't updated by this PR - I moved the version definition to the top-level pom

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 is of course updated in this PR in some modules (Especially in the whole new testsuite, which inherits the version from test-utils-shared)

driver.findElements(By.id("kc-error-message")).stream()
.map(d -> d.getText().trim().split("\\n")[0])
.forEach(s -> params.put("error_description", s));
return new AuthorizationEndpointResponse(params);
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 AuthorizationEndpointResponse is the type, which is dedicated for the OIDC response sent after the redirect from Keycloak back to the client application. It is rather confusing to mis-use for the different purpose (like the case when Keycloak does not redirect back to client, but shows the error).

Is it rather possible to use some different approach? For example returning AuthPageState from the OID4VCBasicWallet.send method and making AuthorizationEndpointResponse as a variable within AuthPageState (which means that for ERROR_PAGE, the response instance would be null and there would be some different variable within AuthPageState, so that caller would be able to easily differentiate whether there was error redirect or Keycloak errorPage + check the appropriate error, which was shown by Keycloak etc).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The Authorization request/response handling follows the same pattern as all the other Foo request/response objects. It is not just a response object that is populated on successful login, like the other APIs it also captures the error cases, namely ...

  • login page does not get displayed, because of an invalid request
  • invalid credentials on login page (i.e. redirect url without code)

In all cases, we don't want to wait for a lengthy timeout, instead return an AuthorizationEndpointResponse with success or error details as soon as we have it.

You are right however, I could simplify that handling a great deal by using the injected ManagedWebDriver.

Anyway, the authorization through the wallet works well for success and error cases without exposure to the low level details of web driver and login forms. In future, we can use the same API for non-interactive authorization flows - as required by ebsi for example.

Please have a look at OID4VCPublicClientTest there we have the (three) use cases that are considered (i.e. success + 2x error cases) - these three should work without running into a timeout.

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.

Sure, I agree it can be good if there is no timeout.

But there is no need to use AuthorizationEndpointResponse for handling the case when the Keycloak shows the error page. That class is used for handling the redirect back to the client as specified in OAuth2 https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2 . Not for showing the error pages at the Keycloak side.

Could be nice to return something different than AuthorizationEndpointResponse from the OID4VCBasicWallet.send , but rather some object (for example OID4VCAuthResponse, which could be for example something like:

public class OID4VCAuthResponse {
    
    private final AuthorizationEndpointResponse authzResponse;
    private final String loginPageError;

    public OID4VCAuthResponse(AuthorizationEndpointResponse authzResponse) {
        // Case when there was redirect to the client (Either with "code" or error redirect with "error" and "error_Description" parameters
       this.authzResponse = authzResponse;
       this.loginPageError = null;
   }

    public OID4VCAuthResponse(String loginPageError) {
        // Case when there was login page error
       this.authzResponse = null;
       this.loginPageError = loginPageError;
   }

Then the calling test would be able to differentiate between the case when there was redirect to client or the case when error shown on the Keycloak side. That is aligned with other Keycloak tests.

@@ -35,6 +35,10 @@ public AuthorizationEndpointResponse(AbstractOAuthClient<?> client) {
}
}

public AuthorizationEndpointResponse(Map<String, String> params) {
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.

I think this should not be needed (see my other comment inside OID4VCBasicWallet).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is unfortunately needed for the invalid credentials case

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.

Please see #45855 (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.

This constructor would be good to remove from this PR (Sorry as I've overlooked it before that it's still kept).

@tdiesler
tdiesler commented Mar 26, 2026 •
Copy link
Copy Markdown
Contributor Author

@mposolda could we possibly do these changes as a follow-up? This PR is the initial setup so that we can work with public clients. Fixing stuff related to public clients is #45851 - I can make a note there about these change requests.

@mposolda
Copy link
Copy Markdown
Contributor

@mposolda could we possibly do these changes as a follow-up? This PR is the initial setup so that we can work with public clients. Fixing stuff related to public clients is #45851 - I can make a note there about these change requests.

Selenium update would be good to address as a follow-up and dedicated issue. But if this PR needs selenium update, then I suppose it should be a pre-requisite rather than a follow-up? But that would be then after Keycloak 26.6.0 release (I hope shortly after, so hopefully next week).

Other issues will be better to address within this PR.

@tdiesler
Copy link
Copy Markdown
Contributor Author

Selenium update would be good to address

The PR doesn't do a selenium update, it reuses the version from the old testsuite

@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.

@tdiesler Thanks for the updates. Added additional inline comment and replied to some of your earlier comments.

}

// No code and no error in response
return new AuthorizationEndpointResponse(Map.of(
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.

Could you check if Invalid username or password is really shown on the page? After submit username/password, there could be many other states happening instead of showing the error (EG. Keycloak could have displayed some additional screen before it is redirected back to the user). So would be good to differentiate instead of returning Invalid username or password when it is actually not really displayed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The login page just gets re-displayed with some text in red that isn't identifiable in selenium (afaik) - we could instead use a more generic error description if you like. However, it the case where the login page got displayed and then some input or verification error happens - we do not deal with retries.

@mposolda mposolda Mar 30, 2026 •
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.

Yes, we can maybe use something generic. Not sure about "generic error description" as in generic case, it is not certain that there is any error displayed. For example there can be the case when username/password is correct, but there is some follow-up page displayed by Keycloak to the user (EG. OTP authentication or required-action with credential-offer or whatever).

If you prefer, it works for me to instead return null in case that there is no code and no error in response. Then it works for me to keep returning AuthorizationEndpointResponse from method send if you prefer that approach. As then the test can do for example something like:

response = wallet.send(username, password);
assertNull(response); // User not redirected yet to the client
loginPage.assertCurrent();
assertEquals('invalid username or password", loginPage.getError());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I prefer to always return a response object, like all the other APIs on OAuthClient and OID4CVIClient

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.

Yes, ok. Then this applies #45855 (comment)

@mposolda mposolda Mar 31, 2026 •
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.

And for this one, it still applies, that it should not return an error as it is not 100% that some error happened. As I've mentioned, after confirm username/password, there may not be the error, but just some additional Keycloak screen. If you are not able to check that error happened, it may work to return something like OID4VCAuthResponse.notAuthzResponseRedirect() .

That should work for any case when context is still on some Keycloak screen and it would be up to the caller to test this further (EG. check if there is error on login screen or there is some additional Keycloak screen).

@tdiesler tdiesler Mar 31, 2026 •
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On the Wallet, I want it to work like this ...

        AuthorizationEndpointResponse authResponse = wallet
                .authorizationRequest()
                .scope(ctx.getScope())
                .send(ctx.getHolder(), TEST_PASSWORD);

        assertEquals("invalid_request", authResponse.getError());
        assertEquals("Missing parameter: code_challenge_method", authResponse.getErrorDescription());

and this ...

        AuthorizationEndpointResponse authResponse = wallet
                .authorizationRequest()
                .scope(ctx.getScope())
                .send(ctx.getHolder(), "xxx");

        assertEquals("unauthorized", authResponse.getError());
        assertNull(authResponse.getErrorDescription(), "Null error description");

in future, we will have ...

        AuthorizationEndpointResponse authResponse = wallet
                .authorizationRequest()
                .scope(ctx.getScope())
                .someOtherRequestHeadersOrParams(...)
                .send();

in all cases, I don't want the caller to deal with login forms, redirect parameters and whatnot. Instead, the response should report success or error (with optional details). If the Authorization Code Flow is being tested, the caller can use the existing API and does not have to go through the Wallet.

Also, let's not forget that this PR is about credential issuance through public clients and not about login form error handling - we can do this later (if really needed).

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.

As I've mentioned many times, the AuthorizationEndpointResponse is used for the cases when the Keycloak redirects to the OAuth client. It should not be used for the cases when Keycloak does not redirect to the client, but is still kept on the login screen or on some additional Keycloak screen.

From your examples, using AuthorizationEndpointResponse for the first example works. But for the second it does not work as it abuses AuthorizationEndpointResponse for different purpose than it was intended.

The test caller should now if it expects redirect to the client or still be kept on some Keycloak screen. If you want to handle both redirect-to-client + still-kept-on-Keycloak, you should use different type for the API than AuthorizationEndpointResponse . Like for example the OID4VCAuthResponse as I've pointed.

If you prefer backwards compatibility for the case when redirect to the client is expected, it may work something like this in OID4VCBasicWallet:

// Backwards compatibility for the case when redirect to client expected
public AuthorizationEndpointResponse send(username, password) {
    OID4VCAuthResponse authResponse = send(username, password, true);
    return authResponse.getAuthzResponse();
}

public OID4VCAuthResponse send(username, password, boolean expectRedirectToClient) {
   OID4VCAuthResponse response = 
   ... The code you had originally, which is able to deal with redirect to client OR keep the context on Keycloak...

   if (expectRedirectToClient) {
       assertNotNull(response.getAuthzResponse());
   } else {
      assertNull(response.getAuthzResponse());
   }
}

public static class OID4VCAuthResponse {
    
    private final AuthorizationEndpointResponse authzResponse;
    private final String loginPageError;

    public OID4VCAuthResponse(AuthorizationEndpointResponse authzResponse) {
        // Case when there was redirect to the client (Either with "code" or error redirect with "error" and "error_Description" parameters
       this.authzResponse = authzResponse;
       this.loginPageError = null;
   }

    public OID4VCAuthResponse(String loginPageError) {
        // Case when there was login page error
       this.authzResponse = null;
       this.loginPageError = loginPageError;
   }

   ... getters etc ...
}

Then for the case when you don't expect redirect to client, the caller can handle it like:

OID4VCAuthResponse oid4vcAuthResponse = wallet.send(username, password, false);
loginPage.assertCurrent();
assertEquals("invalid username or password", loginPage.getError());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This code is gone, please make your peace with it. Improvements to the "error only after timeout" can be made here #47649

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.

Yes, I know. This is rather just something for the future if you still want to support something like this. Added comment to #47649 .

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.url.HostnameV2Test#testDynamicEverything

Keycloak CI - Base IT (6)

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalStateException: Keycloak unexpectedly died :(
	at org.keycloak.testsuite.url.HostnameV2Test.updateServerHostnameSettings(HostnameV2Test.java:243)
	at org.keycloak.testsuite.url.HostnameV2Test.testDynamicEverything(HostnameV2Test.java:120)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
...
jakarta.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8543 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused
	at org.jboss.resteasy.client.jaxrs.engines.ManualClosingApacheHttpClient43Engine.invoke(ManualClosingApacheHttpClient43Engine.java:364)
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:427)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:144)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
...

Report flaky test

@tdiesler
tdiesler commented Mar 31, 2026 •
Copy link
Copy Markdown
Contributor Author

This PR is at the bottom of so many important thing, that I hope to finally unblock it by removing all changes to Wallet.authorizationRequest(). The follow-up issue is here ...

@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.

@tdiesler Thanks for the updates.

The last remaining thing in this PR are changes in pom.xml around selenium. Could you create dedicated GH issue and dedicated PR just for those changes? As this may need to be reviewed by some other members of Keycloak team and should not be done in the same PR, which is related to OID4VCI.

@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.

LGTM with a minor comment for AuthorizationEndpointResponse constructor, which is not used anymore

@@ -35,6 +35,10 @@ public AuthorizationEndpointResponse(AbstractOAuthClient<?> client) {
}
}

public AuthorizationEndpointResponse(Map<String, String> params) {
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.

This constructor would be good to remove from this PR (Sorry as I've overlooked it before that it's still kept).

@tdiesler
tdiesler commented Apr 1, 2026
Copy link
Copy Markdown
Contributor Author

LGTM with a minor comment for AuthorizationEndpointResponse constructor, which is not used anymore

done

tdiesler added 3 commits April 1, 2026 15:31
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
@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.

@tdiesler Thanks!

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.

[OID4VCI] Initial public client for credential issuance

3 participants

0