Search in sources :

Example 1 with TokenResponse

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;
}
Also used : TokenResponse(uk.nhs.digital.intranet.json.TokenResponse)

Example 2 with 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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) TokenResponse(uk.nhs.digital.intranet.json.TokenResponse) AuthorizationException(uk.nhs.digital.intranet.model.exception.AuthorizationException) AccessToken(uk.nhs.digital.intranet.model.AccessToken) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Aggregations

TokenResponse (uk.nhs.digital.intranet.json.TokenResponse)2 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 MultiValueMap (org.springframework.util.MultiValueMap)1 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)1 AccessToken (uk.nhs.digital.intranet.model.AccessToken)1 AuthorizationException (uk.nhs.digital.intranet.model.exception.AuthorizationException)1