Repository navigation
[OID4VCI] Initial public client for credential issuance - #45855
Conversation
200c89c to
b3986fc
Compare
28edf37 to
ecce3a0
Compare
Unreported flaky test detectedIf 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#testLocalCacheClearedOnMergeEventKeycloak CI - Store Model Tests |
There was a problem hiding this comment.
Thanks for this PR @tdiesler !
I added a few comment, could you check them.
There was a problem hiding this comment.
I confirm that my request were all resolved.
Thanks @tdiesler for considering them, PR LGTM.
| @@ -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> | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
selenium isn't updated by this PR - I moved the version definition to the top-level pom
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { | |||
There was a problem hiding this comment.
I think this should not be needed (see my other comment inside OID4VCBasicWallet).
There was a problem hiding this comment.
it is unfortunately needed for the invalid credentials case
There was a problem hiding this comment.
This constructor would be good to remove from this PR (Sorry as I've overlooked it before that it's still kept).
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. |
The PR doesn't do a selenium update, it reuses the version from the old testsuite |
| } | ||
|
|
||
| // No code and no error in response | ||
| return new AuthorizationEndpointResponse(Map.of( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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());
There was a problem hiding this comment.
I prefer to always return a response object, like all the other APIs on OAuthClient and OID4CVIClient
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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());
There was a problem hiding this comment.
This code is gone, please make your peace with it. Improvements to the "error only after timeout" can be made here #47649
There was a problem hiding this comment.
Yes, I know. This is rather just something for the future if you still want to support something like this. Added comment to #47649 .
Unreported flaky test detectedIf 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 |
|
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 ... |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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) { | |||
There was a problem hiding this comment.
This constructor would be good to remove from this PR (Sorry as I've overlooked it before that it's still kept).
done |
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
Signed-off-by: Thomas Diesler <tdiesler@proton.me>
closes #47280
The PR ...
test-app-pubto testrealm.jsonOID4VCIssuerEndpointTest.getCredentialOfferUriUrl()