I created an endpoint to return an access token to my application. When I convert the json from the token to an object called user, postman keeps processing it and reports a timeout. No errors are displayed in the spring boot log. Strangely, if I convert it to a string, the token is returned normally.
My endpoint:
@RequestMapping("/public/token")
@RestController
public class TokenController {
@Value("${KEYCLOAK_URL}")
private String KEYCLOAK_URL;
private static final String CLIENT_ID = "my-app";
private static final String GRANTYPE = "password";
@PostMapping
public ResponseEntity<User> token(@RequestBody Login login) {
HttpHeaders headers = new HttpHeaders();
RestTemplate rt = new RestTemplate();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("client_id", CLIENT_ID);
formData.add("username", login.username);
formData.add("password", login.password);
formData.add("grant_type", GRANTYPE);
HttpEntity<MultiValueMap<String, String>> entity
= new HttpEntity<MultiValueMap<String,String>>(formData, headers);
var user = rt.postForEntity( KEYCLOAK_URL + "/protocol/openid-connect/token", entity, User.class);
return user;
}
public record Login(String username, String password) {}
}
User class
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class User {
@JsonProperty("access_token")
private String acessToken;
@JsonProperty("expires_in")
private Long expiresIn;
@JsonProperty("refresh_expires_in")
private Long refreshExpiresIn;
@JsonProperty("refresh_token")
private String refreshToken;
@JsonProperty("token_type")
private String tokenType;
}
The json conversion from token to user is taking place. I couldn't identify the reason for infinite processing when I return this object.

2 years ago i wrote a Keycloak project for my usage that i think it could be helpful for you
https://github.com/bizhan-laripour/keycloak-sso
This class contains methods for getting token
This class is a dto for populating response
This class is a dto that contains username and password for authorization
This class is A service for getting Token
And this is a controller for getting ssoResponse in a ResponseEntity