If I'm not mistaken then client credentials flow must be explicitly
enabled (Service Accounts Enabled).
https://www.keycloak.org/docs/6.0/server_admin/#_service_accounts
Best,
Łukasz
--
Code-House
http://code-house.org/
On 28.04.2020 20:25, Yuriy Petrov wrote:
> Hello all,
>
> I use Keycloak 6.0.1 and ran into the issue with tokens.
>
> If I run the code
> |
> Keycloakkc =KeycloakBuilder.builder()//
> .serverUrl(/valid-server-url/)//
> .realm(/valid-realm/)//
> .grantType(OAuth2Constants.CLIENT_CREDENTIALS)//
> .clientId(/valid-client/)//
> .clientSecret(/valid-secret/)//
> .resteasyClient(newResteasyClientBuilder().connectionPoolSize(10).build())
> .build();
> AccessTokenResponseat1 =kc.tokenManager().grantToken();
> |
>
> the received at1 object has token null.
>
>
> But if I connect to keycloak as user (not as client as shown above) and
> try to get token
> |
> Keycloakkc =KeycloakBuilder.builder()//
> .serverUrl(/valid-server-url/)//
> .realm(/valid-realm/)//
> .grantType(OAuth2Constants.PASSWORD)//
> .username(/valid-username/)//
> .password(/valid-password/)//
> .clientId(/valid-client/)//
> .clientSecret(/valid-secret/)//
> .resteasyClient(newResteasyClientBuilder().connectionPoolSize(10).build())
> .build();
> AccessTokenResponseat0 =kc2.tokenManager().grantToken();
> |
>
> then the token object at0 has all goodies in it.
>
> In both snippets url, realm, client and secret are the same.
>
> The thing is that I _must_ connect to Keycloak as client.
>
> Can anybody tell me what I'm doing wrong in the first snippet?
>
> Thanks,
> Yuriy
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Keycloak User" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
keycloak-use...@googlegroups.com
> <mailto:
keycloak-use...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/keycloak-user/60903ec0-ae46-4137-afad-7e2002c95095%40googlegroups.com
> <
https://groups.google.com/d/msgid/keycloak-user/60903ec0-ae46-4137-afad-7e2002c95095%40googlegroups.com?utm_medium=email&utm_source=footer>.