Skip to content

Commit

Permalink
Update RestTokenUtil.java
Browse files Browse the repository at this point in the history
Signed-off-by: Manishch22 <[email protected]>
  • Loading branch information
Manishch22 authored Feb 15, 2024
1 parent 5fea8d1 commit 06d6c55
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions mediator/src/main/java/io/mosip/opencrvs/util/RestTokenUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,24 @@ public String getOIDCToken(String tokenEndpoint, String clientId, String clientS
}

private String getOpencrvsAuthTokenInterface(String tokenEndpoint, String clientId, String clientSecret) throws BaseCheckedException{
String body = "{" +
"\"client_id\":\"" + clientId + "\"" + "," +
"\"client_secret\":\"" + clientSecret + "\"" +
"}";
// String body = "{" +
// "\"client_id\":\"" + clientId + "\"" + "," +
// "\"client_secret\":\"" + clientSecret + "\"" +
// "}";
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> request = new HttpEntity<>(body, requestHeaders);
HttpEntity<String> request = new HttpEntity<>(requestHeaders);

UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(tokenEndpoint)
.queryParam("client_id", clientId)
.queryParam("client_secret", clientSecret)
.queryParam("grant_type", "client_credentials");
try{
String responseJson = new RestTemplate().postForObject(tokenEndpoint,request,String.class);
String responseJson = new RestTemplate().postForObject(builder.toUriString(),request,String.class);
if (responseJson == null || responseJson.isEmpty()) {
throw ErrorCode.TOKEN_GENERATION_FAILED.throwChecked();
}
return new JSONObject(responseJson).getString("token");
return new JSONObject(responseJson).getString("access_token");
} catch (JSONException | RestClientException e) {
throw ErrorCode.TOKEN_GENERATION_FAILED.throwChecked(e);
}
Expand Down

0 comments on commit 06d6c55

Please sign in to comment.