Repository navigation
[OID4VCI] Revisit and fix /credential_offer_uri endpoint - #46199
Conversation
2460fa7 to
58a1668
Compare
1c7d141 to
0f6d520
Compare
| } | ||
| CredentialOfferURI credOfferURI = new CredentialOfferURI() | ||
| .setIssuer(credOffer.getCredentialIssuer() + "/protocol/" + OID4VC_PROTOCOL + "/" + CREDENTIAL_OFFER_PATH) | ||
| .setTxCode(offerState.getTxCode()) |
There was a problem hiding this comment.
We should not send tx_code in a response this way. This would make security of this REST endpoint even more broken than it is today.
The tx_code should be shared just with the user. Not with the other parties like administrator or "DataHolder / Issuer portal" application.
In Keycloak, the only reliable way to share things asynchronously with users is via email and that should be default how tx_code would be sent to the users (maybe we can have SPI to consider other ways if someone prefers SMS for example or something else like you're doing here, but that is likely out of scope of this PR).
Ideally, there should be email sent to the user. Once user clicks on the link from the email, Keycloak will display him the page with tx_code from where he can get it and fill inside wallet, which applies for pre-auth codes. @stianst suggested to use action-tokens flow instead of sending directly action-token by email for better security. Some thoughts about this are in this issue: #46269 .
This is additional work and might be not so trivial to implement (if you're not familiar with action-tokens and how they are used in KC). I can help (possibly somewhen next week) and send the initial PR for tx_code support somewhen next week, which then you would be able to consume more easily in this PR. Planning to do that after initial work for #46196 .
There was a problem hiding this comment.
The purpose of this endpoint is to create the credential offer - it is not concerned about how the offer (or parts of it) are delivered to the target value. We can make the return of this endpoint void and have a another endpoint that fetches credential offer state. It would however not fix the issue in principal - just delegate it to some other endpoint.
Please don't forget, the pre-auth grant is designed for cases where a wallet cannot do alternative authorization steps. The assumption that the holder can authenticate with Keycloak in order to use a pre-auth offer is likely flawed - if it could, there would be no need to use a pre-auth offer.
My stance on this is that access to this endpoint must be protected (for the targeted pre-auth case) like any other rest endpoint that allows an admin to do security sensitive stuff (e.g. modify a user's password). the pre-auth code should give access to the offered credential (and nothing else). Getting hold of the pre-auth code would be equivalent to getting hold of any credential that is bound to someone else.
| @QueryParam("credential_configuration_id") String credConfigId, | ||
| @QueryParam("pre_authorized") @DefaultValue("true") boolean preAuthorized, | ||
| @QueryParam("client_id") String appClientId, |
There was a problem hiding this comment.
I think client_id should be still possible and would be good to keep it. The credential-offer permission might not be limited to the single wallet/client, but there are also use-cases where it might be limited to single client.
In relation to that: Specification defines credential_offer_endpoint as additional field in client's metadata where credential offer could be eventually sent. We do not have support for this endpoint, but it indicates that specification counts with the fact that credential-offer could be sent directly to the wallet, which indicates that it is used for particular wallet.
There was a problem hiding this comment.
Let's perhaps do the targeted clientId after preview when we have an actual use case that demands it.
The wallet is not the oauth client.
Yes, we can talk about credential_offer_endpoint (perhaps also after preview) it is however unrelated to targetClient which names the oauth clientId that the (pre-auth) offer is good for.
I removed it for security reasons. The user that has privileges to create a targeted offer (i.e. has the create_credential_offer role) has that privilege only for the current clientId - he cannot create a targeted offer for a clientId that he himself has no access to.
There was a problem hiding this comment.
Let's perhaps do the targeted clientId after preview when we have an actual use case that demands it.
The wallet is not the oauth client.
I think the wallet is client and should be represented by the client in Keycloak. This is assumed in multiple places of the specs and it is clearly mentioned in the specs chapter 2 in the definition of wallet . Especially In the context of this specification, the Wallet acts as an OAuth 2.0 Client (see [RFC6749]) and obtains an Access Token to access an OAuth 2.0 Resource Server (Credential Endpoint). .
The wallet, which is able to do browser authentication with "Authorization code" flow can be regular OIDC client with "Standard flow enabled" and "OID4VCI enabled" . The wallet, which can do only pre-authorized code grant, should be represented by client with "OID4VCI Enabled" and with "PRe-authorized grant enabled" (new switch on the clients. See #46240 for the details).
Also note that pre-authorized grant request itself can use the parameters like client_id or even client authentication. The specs does not mandate, but also does not discourage it as seen in section 6.1 . This allows that credential-offer does not need to have client_id in itself, which would mean that client will need to be identified in pre-authorized grant by the client authentication or the parameter like client_id .
It is probably OK for me to remove the client_id parameter in this REST endpoint in this PR if you prefer. However something to address in the future as we have the requirement for it already within Keycloak team.
I see that credential-permission / credential-offer could be target either to:
- Concrete client. In that case, the grant request (authorization-code or pre-authorized code) is limited only to that single client. In this case, the pre-authorized grant request does not need to include parameter
client_idas it can use the client, which has available permission of this user - Not specific to concrete client. In that case, the grant request will need to identify the client_id of the wallet . The pre-authorized grant request will need to include parameter
client_id.
3f6d20d to
31e0596
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.broker.KcOidcBrokerTest#loginWithExistingUserWithBruteForceEnabledKeycloak CI - Java Distribution IT (windows-latest - temurin - 17) |
1ecb63f to
1dd04f5
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 |
|
Before I restore Also, before I remove the Here is what you get with this PR ...
We recognize that there is still work to do - for example
This PR is likely a dependency of #46327 |
3f70043 to
2cf888e
Compare
Yeah, the first two points are great additions IMO. Especially the first one (the uri+qr can be always done on the issuer-portal side as when only the "uri" is returned, the application can still create QR code in themselves programaticaly with the use of some library like for example Google ZXing for Java. But I see it is more convenient to possibly have ability to return both at the same time). For the
Would probably see (1) as better, so we can divide the work into multiple PRs. WDYT?
Yes, this is work to do, but possibly for the follow-ups. What we discussed within Keycloak team is to:
I don't see those PRs as being dependency of each other. UI from #46327 should not need to use the REST endpoint of this one. The login themes pages in general are not using REST endpoints as those are built by Keycloak itself. Also the access-token is not available yet for the user at the time when this page is rendered (although user was in fact authenticated in Keycloak). But I can see it can probably re-use some Java code from both places though. |
|
Regading the That other option could be some endpoint that is only available to test cases. |
I don't think the |
Ok, done - it is now redacted with test coverage preserved. |
Thanks. However can you please remove |
|
It is redacted to indicate that it exists on the server or to indicate that the pre-auth code in the offer is useless on its own. Also, testing for a redacted tx_code has value already, imho. How about we remove it when there actually is an alternative way to see it? |
fdd66da to
2301294
Compare
Yes, automated tests are OK for now until we have |
|
I want the caller to know that the system has created a value. If I remove it, the caller is left wondering whether the tx_code parameter had any effect. Can we not leave it as it is? A |
Signed-off-by: Thomas Diesler <tdiesler@ibm.com>
Signed-off-by: Thomas Diesler <tdiesler@ibm.com>
) closes keycloak#45005 Signed-off-by: Thomas Diesler <tdiesler@ibm.com>
closes #45005
Discussion: #46202