Repository navigation
[OID4VCI] Migrate CredentialsOffer to multiple grant types - Part2 #46947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
services/src/main/java/org/keycloak/protocol/oid4vc/model/CredentialOfferGrant.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright 2026 Red Hat, Inc. and/or its affiliates | ||
| * and other contributors as indicated by the @author tags. | ||
|
tdiesler marked this conversation as resolved.
Resolved
|
||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.keycloak.protocol.oid4vc.model; | ||
|
|
||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
|
||
| /** | ||
| * Container for the grants to be used in a Credential Offer | ||
| * <p> | ||
| * {@see https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#name-credential-offer} | ||
| * | ||
| * @author <a href="mailto:tdiesler@ibm.com">Thomas Diesler</a> | ||
| */ | ||
| public interface CredentialOfferGrant { | ||
|
|
||
| @JsonIgnore | ||
| String getGrantType(); | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
...s/src/main/java/org/keycloak/protocol/oid4vc/model/CredentialOfferGrantsDeserializer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.keycloak.protocol.oid4vc.model; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonParser; | ||
| import com.fasterxml.jackson.databind.DeserializationContext; | ||
| import com.fasterxml.jackson.databind.JsonDeserializer; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.exc.InvalidFormatException; | ||
|
|
||
| import static org.keycloak.protocol.oid4vc.model.AuthorizationCodeGrant.AUTH_CODE_GRANT_TYPE; | ||
| import static org.keycloak.protocol.oid4vc.model.PreAuthorizedCodeGrant.PRE_AUTH_GRANT_TYPE; | ||
|
|
||
| public final class CredentialOfferGrantsDeserializer extends JsonDeserializer<Map<String, CredentialOfferGrant>> { | ||
|
|
||
| @Override | ||
| public Map<String, CredentialOfferGrant> deserialize(JsonParser p, DeserializationContext ctx) throws IOException { | ||
|
|
||
| Map<String, CredentialOfferGrant> grants = new LinkedHashMap<>(); | ||
| var mapper = (ObjectMapper) p.getCodec(); | ||
| var node = mapper.readTree(p); | ||
|
|
||
| var fields = node.fieldNames(); | ||
| while (fields.hasNext()) { | ||
| var grantType = fields.next(); | ||
| var valueNode = node.get(grantType); | ||
|
|
||
| Class<? extends CredentialOfferGrant> target = | ||
| switch (grantType) { | ||
| case AUTH_CODE_GRANT_TYPE -> AuthorizationCodeGrant.class; | ||
| case PRE_AUTH_GRANT_TYPE -> PreAuthorizedCodeGrant.class; | ||
| default -> throw new InvalidFormatException( | ||
| p, "Unknown grant type key: " + grantType, grantType, CredentialOfferGrant.class); | ||
| }; | ||
|
|
||
| CredentialOfferGrant grant = mapper.treeToValue(valueNode, target); | ||
| grants.put(grantType, grant); | ||
| } | ||
| return grants; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per my review, this is the main point of this PR. Could you clarify how this will be leveraged (in a subsequent PR?) and what are security concerns if the wallet sends back an unexpected value? My apologies if that's asking you to repeat yourself.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is part of PR #46950
Currently, the issuer state is simply the base64 encoded CredentialOfferState.Id
With so many "identifiers" floating around, it is perhaps useful to mention that this id is a server generated opaque id that identifies the internal CredentialOfferState. The offer state can now be retrieved using these three keys ...
Also worth noting, that
credential_identifieris no longer a key by which an offer state can be found. Instead it is (as intended by the spec) an identifier for a variation of claims that are available for a givencredential_configuration_id. It is a property defined by the Issuer (i.e.vc.credential_identifier) on the client scope. It is no longer generated nor is it necessarily a UUID - I changed the test accordingly.Currently, we only support a single value for this property - it should be multiple and there should be some mapping that results in different claims or claim values depending on
credential_identifier#46264
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed context. It helps a lot to have
CredentialOfferState.Id. I was even planning to add it for for JWT pre auth code PR I'm working on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UR welcome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can turn to be quite complicated, but depends on what exactly is in the scope for this "mapping support" . For me, the 1:1 mapping between
credential_configuration_idandcredential_identifierwould be OK and it is sufficient to support just that for OID4VCI specification support as it is up to the Keycloak (Issuer) on whatcredential_identifiersit returns in the tokenResponse insideauthorization_details. But support for "Authorization groups" of user profile would be likely OK . Added comment to the #46264 as I guess that is rather a place where to discuss the details of this?