diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index f28e1e4bad..d93c44ccb8 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -744,6 +744,9 @@ public class RealmAdapter implements RealmModel { @Override public ClientModel addClient(String id, String clientId) { + if (clientId == null) { + clientId = id; + } ClientEntity entity = new ClientEntity(); entity.setId(id); entity.setClientId(clientId); diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java index 57a9e3838c..bae4589b33 100755 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java @@ -853,6 +853,11 @@ public class RealmAdapter extends AbstractMongoAdapter impleme clientEntity.setStandardFlowEnabled(true); getMongoStore().insertEntity(clientEntity, invocationContext); + if (clientId == null) { + clientEntity.setClientId(clientEntity.getId()); + getMongoStore().updateEntity(clientEntity, invocationContext); + } + final ClientModel model = new ClientAdapter(session, this, clientEntity, invocationContext); session.getKeycloakSessionFactory().publish(new ClientCreationEvent() { @Override diff --git a/services/src/main/java/org/keycloak/services/clientregistration/AbstractClientRegistrationProvider.java b/services/src/main/java/org/keycloak/services/clientregistration/AbstractClientRegistrationProvider.java index 683bb14d58..ffda262dd9 100755 --- a/services/src/main/java/org/keycloak/services/clientregistration/AbstractClientRegistrationProvider.java +++ b/services/src/main/java/org/keycloak/services/clientregistration/AbstractClientRegistrationProvider.java @@ -51,9 +51,6 @@ public abstract class AbstractClientRegistrationProvider implements ClientRegist try { ClientModel clientModel = RepresentationToModel.createClient(session, session.getContext().getRealm(), client, true); - if (client.getClientId() == null) { - clientModel.setClientId(clientModel.getId()); - } client = ModelToRepresentation.toRepresentation(clientModel);