# Create a client using keycloak admin Java SDK that has authentication and authorization enabled

**URL:** <https://forum.keycloak.org/t/create-a-client-using-keycloak-admin-java-sdk-that-has-authentication-and-authorization-enabled/24900>\
**Category:** Miscellanaeous\
**Created:** [March 5, 2024, 8:55pm UTC](https://forum.keycloak.org/t/create-a-client-using-keycloak-admin-java-sdk-that-has-authentication-and-authorization-enabled/24900 "2024-03-05T20:55:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndtreviv](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/ndtreviv/32/9944_2.png) [@ndtreviv](https://forum.keycloak.org/u/ndtreviv)\
**Post date:** [March 5, 2024, 8:55pm UTC](https://forum.keycloak.org/t/create-a-client-using-keycloak-admin-java-sdk-that-has-authentication-and-authorization-enabled/24900/1 "2024-03-05T20:55:03Z")

</div>

I’m using the keycloak admin Java library to create a client, like so:

```java
ClientRepresentation client = new ClientRepresentation();
client.setClientId(clientId);
client.setName(clientId);
client.setStandardFlowEnabled(true);
client.setAuthorizationServicesEnabled(true);
client.setDirectAccessGrantsEnabled(true);
client.setPublicClient(true);
client.setEnabled(true);
client.setSecret(secret);
client.setServiceAccountsEnabled(true);
client.setAlwaysDisplayInConsole(true);
client.setDefaultClientScopes(List.of(Scopes.OPENID, Scopes.PROFILE, Scopes.EMAIL, Scopes.ROLES));
client.setRedirectUris(List.of(publicUrl + "/*"));
realm.clients().create(client);

```

I’m trying to turn these two switches on:

 ![Screenshot 2024-03-05 at 20.47.45](https://global.discourse-cdn.com/free1/uploads/keycloak/original/2X/e/e4b16dd246cba2cb21776143c5155683d9e8dadb.png)

I can’t find appropriate properties to set on the client to make this happen.  
How do I do it?

Many thanks for any help offered.

---

<div class="post-metadata">

**Author:** ![ndtreviv](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/ndtreviv/32/9944_2.png) [@ndtreviv](https://forum.keycloak.org/u/ndtreviv)\
**Post date:** [March 6, 2024, 10:41am UTC](https://forum.keycloak.org/t/create-a-client-using-keycloak-admin-java-sdk-that-has-authentication-and-authorization-enabled/24900/2 "2024-03-06T10:41:35Z")

</div>

To try and work this out I created a client using the UI and examined the data it posted to the API endpoint.

What I was missing was these attributes:

```auto
{
    "oauth2.device.authorization.grant.enabled": false,
    "oidc.ciba.grant.enabled": false,
    "login_theme": "",
    "display.on.consent.screen": false,
    "backchannel.logout.url": "",
    "backchannel.logout.session.required": "true",
    "backchannel.logout.revoke.offline.tokens": "false"
}

```

So I started setting those attributes:

```java
...
        clientRepresentation.setAttributes(Map.of(
                "oauth2.device.authorization.grant.enabled", "false",
                "oidc.ciba.grant.enabled", "false",
                "login_theme", "base",
                "display.on.consent.screen", "false",
                "backchannel.logout.url", "",
                "backchannel.logout.session.required", "true",
                "backchannel.logout.revoke.offline.tokens", "false"
        ));
        clientResource.update(clientRepresentation);

```

But those two switches still don’t turn on. From what I can tell:

```java
clientRepresentation.setAuthorizationServicesEnabled(true);

```

should do it, but it clearly doesn’t, which makes me wonder if this is actually a keycloak admin bug?

I’m using `keycloak-admin-client`:

```auto
implementation group: 'org.keycloak', name: 'keycloak-admin-client', version: '24.0.0'

```

and the keycloak docker image: `quay.io/keycloak/keycloak:24.0.0`

I’m considering raising a bug report.

---

<div class="post-metadata">

**Author:** ![ndtreviv](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/ndtreviv/32/9944_2.png) [@ndtreviv](https://forum.keycloak.org/u/ndtreviv)\
**Post date:** [March 6, 2024, 12:59pm UTC](https://forum.keycloak.org/t/create-a-client-using-keycloak-admin-java-sdk-that-has-authentication-and-authorization-enabled/24900/3 "2024-03-06T12:59:29Z")

</div>

D’oh! 🤦 Figured it out.

I was setting: `clientRepresentation.setPublicClient(true);`, but that needs to be `false`, then it all works as expected.
