I am going to call Azure Resource Management Rest API from my Spring Boot application. For that i need to have authorization token. After googling thorough different sources, i could understand that we need to call POST API to generate Authorization token using below URL;
https://login.microsoftonline.com/{tenant_id}/oauth2/token
with below request body, Below details i have got by creating service principle and Active directory
client_secret
resource
grant_type
tenant_id
Spring boot java code:
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
String url= "https://login.microsoftonline.com/{tenant_id}/oauth2/token";
AuthTokenBody authTokenBody = service.setBody();
headers.setContentType(MediaType.APPLICATION_JSON);
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
HttpEntity<AuthTokenBody> entity = new HttpEntity<>(authTokenBody, headers);
ResponseEntity response= restTemplate.postForObject(url, entity, ResponseEntity.class);
But i get below error:
{ "timestamp": "2018-12-23T11:52:58.175+0000", "status": 500, "error": "Internal Server Error", "message": "400 Bad Request", "path": "/cdaas/app" }
Can you please guide how to call generate Authentication code in Spring-boot to cal Azure Resource management.
Thank you in advance