How to register/create a new User (Role User) in Keycloak via Spring Boot?
(Register a new User in the provided "Register" Web Page from Keycloak is working)
This is my Controller:
I am able to provide Resources for Entities with the Role User or Admin.
But how can I register, login, logout from Keycloak without using the provided Web Interface (But using Spring Boot)?
@RestController
@RequestMapping("/Hello")
public class HelloController {
@RequestMapping(value = "/helloWorld", method = RequestMethod.GET)
public ResponseEntity<String> getHello() {
return ResponseEntity.ok("Hello World");
}
//Only possible with Access Token of an Account which has the Role Admin
@RolesAllowed("admin")
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public ResponseEntity<String> getAdmin(@RequestHeader String Authorization) {
return ResponseEntity.ok("Hello Admin");
}
}
This is my application.yml:
server:
port: 8081
keycloak:
realm: SpringBootHelloKeycloak
auth-server-url: http://localhost:8180/auth
ssl-required: external
resource: login-app
credentials:
secret: c0a68675-8f16-4a13-83dd-6d2111d74ee6
use-resource-role-mappings: true
bearer-only: true
Is there any example or any Library for this purpose? Thank you very much in advance