Reputation: 51
I am consuming the endpoints of keycloak, I work with OAuth resource server, I want to use http://localhost:port/auth/realms/myrealm/protocol/openid-connect/token
to get token but I got i don't know how to de redirection from my spring endpoint to keycloak endpoint
Here is my trial but it's not working
public LoginData login(@RequestBody LoginData logindata){
MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
Map map = new HashMap<String, String>();
map.put("Content-Type", "application/x-www-form-urlencoded");
headers.setAll(map);
HttpEntity<LoginData> entity = new HttpEntity<LoginData>(logindata,headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<LoginData> response = restTemplate.exchange(
"http://localhost:port/auth/realms/myrealm/protocol/openid-connect/token", HttpMethod.POST, entity, LoginData.class);
System.out.println(response);
return response.getBody();
}
Upvotes: 0
Views: 408
Reputation: 1592
Why do you need to call this endpoint. Just integrate with Spring security oauth2-client lib
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
Or If you want to integrate with proprietary Keycloak lib, use Keycloak adapter for spring
With spring oauth2, you will need to use additional configuration like
spring.security.oauth2.client.registration
spring.security.oauth2.client.provider.keycloak
This is not a complete answer but just a direction
Upvotes: 1