use of uk.nhs.digital.intranet.model.AccessToken in project hippo by NHS-digital-website.
the class AccessTokenEncoderTest method encodesAndDecodesAccessToken.
@Test
public void encodesAndDecodesAccessToken() {
final AccessToken initialAccessToken = new AccessToken("token", "refresh", 1000);
final AccessTokenEncoder encoder = new AccessTokenEncoder();
final String base64String = encoder.encode(initialAccessToken);
final AccessToken resultAccessToken = encoder.decode(base64String);
assertEquals(initialAccessToken.getToken(), resultAccessToken.getToken());
assertEquals(initialAccessToken.getRefreshToken(), resultAccessToken.getRefreshToken());
assertEquals(initialAccessToken.getExpirationDate(), resultAccessToken.getExpirationDate());
}
use of uk.nhs.digital.intranet.model.AccessToken in project hippo by NHS-digital-website.
the class AccessTokenValve method getNewAccessToken.
private AccessToken getNewAccessToken(final HstRequestContext requestContext, final AccessToken accessToken) throws AuthorizationException {
try {
final String refreshToken = getCookie(requestContext.getServletRequest(), Constants.REFRESH_TOKEN_COOKIE_NAME).map(Cookie::getValue).orElse(null);
final AccessToken completeAccessToken = new AccessToken(accessToken.getToken(), refreshToken, accessToken.getExpirationDate());
final AccessToken newAccessToken = authorizationProvider.refreshAccessToken(completeAccessToken);
final Cookie accessTokenCookie = cookieProvider.getAccessTokenCookie(newAccessToken);
final Cookie refreshTokenCookie = cookieProvider.getRefreshTokenCookie(newAccessToken);
requestContext.getServletResponse().addCookie(accessTokenCookie);
requestContext.getServletResponse().addCookie(refreshTokenCookie);
return newAccessToken;
} catch (final AuthorizationException e) {
LOGGER.error("Received exception with status code {} from Microsoft Graph API when trying to refresh access token.", e.getStatusCode().value(), e.getCause());
throw e;
}
}
use of uk.nhs.digital.intranet.model.AccessToken in project hippo by NHS-digital-website.
the class CookieProviderTest method returnsEncodedAccessTokenCookie.
@Test
public void returnsEncodedAccessTokenCookie() {
final AccessToken accessToken = new AccessToken("token", "refresh-token", 10);
final Cookie cookie = cookieProvider.getAccessTokenCookie(accessToken);
assertEquals(Constants.ACCESS_TOKEN_COOKIE_NAME, cookie.getName());
assertEquals(2592000, cookie.getMaxAge());
assertEquals("/", cookie.getPath());
assertEquals("expected_returned_value", cookie.getValue());
}
use of uk.nhs.digital.intranet.model.AccessToken in project hippo by NHS-digital-website.
the class CookieProviderTest method returnsRefreshTokenCookie.
@Test
public void returnsRefreshTokenCookie() {
final AccessToken accessToken = new AccessToken("token", "refresh-token", 10);
final Cookie cookie = cookieProvider.getRefreshTokenCookie(accessToken);
assertEquals(Constants.REFRESH_TOKEN_COOKIE_NAME, cookie.getName());
assertEquals(2592000, cookie.getMaxAge());
assertEquals("/", cookie.getPath());
assertEquals("refresh-token", cookie.getValue());
}
use of uk.nhs.digital.intranet.model.AccessToken in project hippo by NHS-digital-website.
the class AuthenticationResourceTest method requestsAccessTokenAndSavesCookieAndRedirectsToUri.
@Test
public void requestsAccessTokenAndSavesCookieAndRedirectsToUri() throws Exception {
final AccessToken accessToken = new AccessToken("token", "refresh", 1);
final Cookie accessTokenCookie = new Cookie("accessToken", "access_token_value");
final Cookie refreshTokenCookie = new Cookie("refreshToken", "access_token_value");
when(authorizationProvider.processAuthorizationResponse(AUTHORIZATION_CODE)).thenReturn(accessToken);
when(cookieProvider.getAccessTokenCookie(accessToken)).thenReturn(accessTokenCookie);
when(cookieProvider.getRefreshTokenCookie(accessToken)).thenReturn(refreshTokenCookie);
authenticationResource.processResponse(response, AUTHORIZATION_CODE);
verify(response).addCookie(accessTokenCookie);
verify(response).addCookie(refreshTokenCookie);
verify(response).sendRedirect(REDIRECT_URI);
}
Aggregations