I've tried integrating Keycloak as an authentication feature for my Spring Boot App, but whenever I make requests through Postman I get 403 errors (or 401 if I attempt to set some authentication token - thus far I've only worked with JWTs and there it was relatively straight forward to acquire one. Login with an account and then use that token, however Keycloak uses Cookies and I'm not entirely sure which one to pick (or to pick one at all). This - or adding some missing permissions - is the most likely case of a problem.).
Controller class:
private static final Keycloak keycloak = KeycloakBuilder.builder()
.serverUrl(someURL)
.realm(keycloakRealm)
.username(someUsername)
.password(somePassword)
.clientId("admin-cli")
.resteasyClient(
new ResteasyClientBuilder()
.connectionPoolSize(10).build()
).build();
... Generic CRUD Methods
Properties:
server.port=8083
keycloak.realm=$someRealm
keycloak.resource=$someApi
keycloak.auth-server-url= $someURL
keycloak.ssl-required=external
keycloak.public-client=true
keycloak.principal-attribute=preferred_username
server.ssl.key-store=classpath:$somewhere
server.ssl.key-store-password=$something
# JKS or PKCS12
server.ssl.keyStoreType=PKCS12
# Spring Security
security.require-ssl=true
Pom:
I only listed the Keycloak dependencies here, in case I'm missing one.
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
<version>12.0.4</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>12.0.4</version>
</dependency>
It's most likely that I've missed something, as logging in works, but using the keycloak-admin-client-api doesn't.
Searching for solutions, I've not found anything that helped yet.