8000 [OID4VCI] Add support for CredentialScopeRepresentation by tdiesler · Pull Request #46356 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@
import static org.keycloak.VCFormat.SD_JWT_VC;
import static org.keycloak.constants.OID4VCIConstants.OID4VC_PROTOCOL;
import static org.keycloak.models.ClientScopeModel.INCLUDE_IN_TOKEN_SCOPE;
import static org.keycloak.models.oid4vci.CredentialScopeModel.CONFIGURATION_ID;
import static org.keycloak.models.oid4vci.CredentialScopeModel.CONTEXTS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.CRYPTOGRAPHIC_BINDING_METHODS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.CRYPTOGRAPHIC_BINDING_METHODS_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.EXPIRY_IN_SECONDS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.EXPIRY_IN_SECONDS_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.FORMAT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.HASH_ALGORITHM;
import static org.keycloak.models.oid4vci.CredentialScopeModel.HASH_ALGORITHM_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.INCLUDE_IN_METADATA;
import static org.keycloak.models.oid4vci.CredentialScopeModel.SD_JWT_DECOYS_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.SD_JWT_NUMBER_OF_DECOYS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.SD_JWT_VISIBLE_CLAIMS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.SD_JWT_VISIBLE_CLAIMS_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.TOKEN_JWS_TYPE;
import static org.keycloak.models.oid4vci.CredentialScopeModel.TOKEN_TYPE_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.TYPES;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VCT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_BUILD_CONFIG_HASH_ALGORITHM;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_BUILD_CONFIG_HASH_ALGORITHM_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_BUILD_CONFIG_SD_JWT_VISIBLE_CLAIMS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_BUILD_CONFIG_SD_JWT_VISIBLE_CLAIMS_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_BUILD_CONFIG_TOKEN_JWS_TYPE;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_BUILD_CONFIG_TOKEN_JWS_TYPE_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_CONFIGURATION_ID;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_CONTEXTS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_CRYPTOGRAPHIC_BINDING_METHODS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_EXPIRY_IN_SECONDS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_EXPIRY_IN_SECONDS_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_FORMAT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_INCLUDE_IN_METADATA;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_SD_JWT_NUMBER_OF_DECOYS;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_SD_JWT_NUMBER_OF_DECOYS_DEFAULT;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_SUPPORTED_TYPES;

/**
* Factory for creating all OID4VC related endpoints and the default mappers.
Expand Down Expand Up @@ -156,8 +156,8 @@ public void setupClientDefaults(ClientRepresentation rep, ClientModel newClient)
public void addClientScopeDefaults(ClientScopeRepresentation clientScope) {
String scopeName = clientScope.getName();

clientScope.getAttributes().computeIfAbsent(FORMAT, k -> VCFormat.getFromScope(scopeName));
String format = clientScope.getAttributes().get(FORMAT);
clientScope.getAttributes().computeIfAbsent(VC_FORMAT, k -> VCFormat.getFromScope(scopeName));
String format = clientScope.getAttributes().get(VC_FORMAT);

int idx = scopeName.lastIndexOf(VCFormat.getScopeSuffix(format));
String credentialType = idx > 0 ? scopeName.substring(0, idx) : scopeName;
Expand All @@ -167,19 +167,19 @@ public void addClientScopeDefaults(ClientScopeRepresentation clientScope) {
// clientScope.getAttributes().computeIfAbsent(ISSUER_DID, k -> <generate did or use the realm url>)

clientScope.getAttributes().putIfAbsent(INCLUDE_IN_TOKEN_SCOPE, "true");
clientScope.getAttributes().putIfAbsent(INCLUDE_IN_METADATA, "true");
clientScope.getAttributes().putIfAbsent(CONFIGURATION_ID, scopeName);
clientScope.getAttributes().putIfAbsent(TYPES, credentialType);
clientScope.getAttributes().putIfAbsent(CONTEXTS, credentialType);
clientScope.getAttributes().putIfAbsent(VC_INCLUDE_IN_METADATA, "true");
clientScope.getAttributes().putIfAbsent(VC_CONFIGURATION_ID, scopeName);
clientScope.getAttributes().putIfAbsent(VC_SUPPORTED_TYPES, credentialType);
clientScope.getAttributes().putIfAbsent(VC_CONTEXTS, credentialType);
clientScope.getAttributes().putIfAbsent(VCT, credentialType);
clientScope.getAttributes().putIfAbsent(CRYPTOGRAPHIC_BINDING_METHODS, CRYPTOGRAPHIC_BINDING_METHODS_DEFAULT);
clientScope.getAttributes().putIfAbsent(HASH_ALGORITHM, HASH_ALGORITHM_DEFAULT);
clientScope.getAttributes().putIfAbsent(TOKEN_JWS_TYPE, TOKEN_TYPE_DEFAULT);
clientScope.getAttributes().putIfAbsent(EXPIRY_IN_SECONDS, String.valueOf(EXPIRY_IN_SECONDS_DEFAULT));
clientScope.getAttributes().putIfAbsent(VC_CRYPTOGRAPHIC_BINDING_METHODS, CRYPTOGRAPHIC_BINDING_METHODS_DEFAULT);
clientScope.getAttributes().putIfAbsent(VC_BUILD_CONFIG_HASH_ALGORITHM, VC_BUILD_CONFIG_HASH_ALGORITHM_DEFAULT);
clientScope.getAttributes().putIfAbsent(VC_BUILD_CONFIG_TOKEN_JWS_TYPE, VC_BUILD_CONFIG_TOKEN_JWS_TYPE_DEFAULT);
clientScope.getAttributes().putIfAbsent(VC_EXPIRY_IN_SECONDS, String.valueOf(VC_EXPIRY_IN_SECONDS_DEFAULT));

if (SD_JWT_VC.equals(format)) {
clientScope.getAttributes().putIfAbsent(SD_JWT_NUMBER_OF_DECOYS, String.valueOf(SD_JWT_DECOYS_DEFAULT));
clientScope.getAttributes().putIfAbsent(SD_JWT_VISIBLE_CLAIMS, SD_JWT_VISIBLE_CLAIMS_DEFAULT);
clientScope.getAttributes().putIfAbsent(VC_SD_JWT_NUMBER_OF_DECOYS, String.valueOf(VC_SD_JWT_NUMBER_OF_DECOYS_DEFAULT));
clientScope.getAttributes().putIfAbsent(VC_BUILD_CONFIG_SD_JWT_VISIBLE_CLAIMS, VC_BUILD_CONFIG_SD_JWT_VISIBLE_CLAIMS_DEFAULT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import static org.keycloak.OID4VCConstants.OPENID_CREDENTIAL;
import static org.keycloak.constants.OID4VCIConstants.CREDENTIAL_OFFER_CREATE;
import static org.keycloak.co 8000 nstants.OID4VCIConstants.OID4VC_PROTOCOL;
import static org.keycloak.models.oid4vci.CredentialScopeModel.VC_CONFIGURATION_ID;
import static org.keycloak.protocol.oid4vc.model.ErrorType.INVALID_CREDENTIAL_OFFER_REQUEST;
import static org.keycloak.protocol.oid4vc.model.ErrorType.INVALID_CREDENTIAL_REQUEST;
import static org.keycloak.protocol.oid4vc.model.ErrorType.UNKNOWN_CREDENTIAL_CONFIGURATION;
Expand Down Expand Up @@ -470,7 +471,7 @@ public Response createCredentialOffer(
//
ClientScopeModel credentialClientScope = session.clientScopes()
.getClientScopesByProtocol(realmModel, OID4VC_PROTOCOL)
.filter(it -> credConfigId.equals(it.getAttribute(CredentialScopeModel.CONFIGURATION_ID)))
.filter(it -> credConfigId.equals(it.getAttribute(VC_CONFIGURATION_ID)))
.findFirst()
.orElse(null);
if (credentialClientScope == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected List<ProviderConfigProperty> getIndividualConfigProperties() {
*/
@Override
public boolean includeInMetadata() {
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.INCLUDE_IN_METADATA))
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.VC_INCLUDE_IN_METADATA))
.map(Boolean::parseBoolean)
.orElse(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected List<ProviderConfigProperty> getIndividualConfigProperties() {
*/
@Override
public boolean includeInMetadata() {
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.INCLUDE_IN_METADATA))
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.VC_INCLUDE_IN_METADATA))
.map(Boolean::parseBoolean)
.orElse(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected List<ProviderConfigProperty> getIndividualConfigProperties() {
*/
@Override
public boolean includeInMetadata() {
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.INCLUDE_IN_METADATA))
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.VC_INCLUDE_IN_METADATA))
.map(Boolean::parseBoolean)
.orElse(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public OID4VCMapper setMapperModel(ProtocolMapperModel mapperModel, String forma
* attributes from the metadata
*/
public boolean includeInMetadata() {
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.INCLUDE_IN_METADATA))
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.VC_INCLUDE_IN_METADATA))
.map(Boolean::parseBoolean)
.orElse(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected List<ProviderConfigProperty> getIndividualConfigProperties() {
*/
@Override
public boolean includeInMetadata() {
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.INCLUDE_IN_METADATA))
return Optional.ofNullable(mapperModel.getConfig().get(CredentialScopeModel.VC_INCLUDE_IN_METADATA))
.map(Boolean::parseBoolean)
.orElse(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public static CredentialBuildConfig parse(KeycloakSession keycloakSession,
return new CredentialBuildConfig().setCredentialIssuer(credentialIssuer)
.setCredentialConfigId(credentialConfiguration.getId())
.setCredentialType(credentialModel.getVct())
.setTokenJwsType(credentialModel.getTokenJwsType())
.setTokenJwsType(credentialModel.getBuildConfigTokenJwsType())
.setNumberOfDecoys(credentialModel.getSdJwtNumberOfDecoys())
.setSigningKeyId(credentialModel.getSigningKeyId())
.setSigningAlgorithm(signingAlg)
.setHashAlgorithm(credentialModel.getHashAlgorithm())
.setSdJwtVisibleClaims(credentialModel.getSdJwtVisibleClaims());
.setHashAlgorithm(credentialModel.getBuildConfigHashAlgorithm())
.setSdJwtVisibleClaims(credentialModel.getBuildConfigSdJwtVisibleClaims());
}

public String getCredentialIssuer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ public Optional<CredentialScopeModel> findCredentialScope(KeycloakSession keyclo
Map<String, String> searchAttributeMap =
Optional.ofNullable(credentialConfigurationId)
.map(credentialIdentifier -> {
return Map.of(CredentialScopeModel.CONFIGURATION_ID, credentialConfigurationId);
return Map.of(CredentialScopeModel.VC_CONFIGURATION_ID, credentialConfigurationId);
}).orElseGet(() -> {
return Map.of(CredentialScopeModel.CREDENTIAL_IDENTIFIER, credentialIdentifier);
return Map.of(CredentialScopeModel.VC_IDENTIFIER, credentialIdentifier);
});

RealmModel currentRealm = keycloakSession.getContext().getRealm();
Expand Down
Loading
Loading
0