use of uk.nhs.digital.intranet.json.TokenResponse in project hippo by NHS-digital-website.
the class MicrosoftGraphAuthorizationProviderTest method getTokenResponse.
private static TokenResponse getTokenResponse() {
final TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setAccessToken(TOKEN);
tokenResponse.setRefreshToken(REFRESH_TOKEN);
tokenResponse.setExpiresIn(EXPIRES_IN);
return tokenResponse;
}
use of uk.nhs.digital.intranet.json.TokenResponse in project hippo by NHS-digital-website.
the class MicrosoftGraphAuthorizationProvider method getAccessToken.
private AccessToken getAccessToken(MultiValueMap<String, String> map) throws AuthorizationException {
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
final HttpEntity<MultiValueMap<String, String>> httpRequest = new HttpEntity<>(map, headers);
try {
final ResponseEntity<TokenResponse> responseEntity = restTemplate.postForEntity(URI.create(baseUri + "token"), httpRequest, TokenResponse.class);
final TokenResponse tokenResponse = responseEntity.getBody();
Assert.notNull(tokenResponse, "Received null response from Microsoft Graph API.");
return new AccessToken(tokenResponse.getAccessToken(), tokenResponse.getRefreshToken(), tokenResponse.getExpiresIn());
} catch (final HttpStatusCodeException e) {
throw new AuthorizationException(e.getStatusCode(), e);
}
}
Aggregations