OAuth2TokenExtractor { void refreshAccessToken(OAuth2Parameters parameters) throws OAuthProblemException, OAuthSystemException { OAuthClientRequest accessTokenRequest = OAuthClientRequest .tokenLocation(parameters.accessTokenUri) .setGrantType(GrantType.REFRESH_TOKEN) .setClientId(parameters.clientId) .setClientSecret(parameters.clientSecret) .setRefreshToken(parameters.refreshToken) .buildBodyMessage(); OAuthClient oAuthClient = getOAuthClient(); OAuthToken oAuthToken = oAuthClient.accessToken(accessTokenRequest, OAuthJSONAccessTokenResponse.class).getOAuthToken(); parameters.applyRetrievedAccessToken(oAuthToken.getAccessToken()); parameters.setAccessTokenIssuedTimeInProfile(TimeUtils.getCurrentTimeInSeconds()); String newRefreshToken = oAuthToken.getRefreshToken(); if (newRefreshToken!=null && !newRefreshToken.equals(parameters.refreshToken)) { parameters.setRefreshTokenInProfile(newRefreshToken); } }  void extractAccessToken(final OAuth2Parameters parameters); OAuthClientRequest getClientRequestForROPC(final OAuth2Parameters parameters); void extractAccessTokenForClientCredentialsGrant(final OAuth2Parameters parameters); OAuthClientRequest getClientRequestForClientCredentialsGrant(final OAuth2Parameters parameters); void addBrowserListener(BrowserListener listener); static final String CODE; static final String TITLE; static final String TOKEN; static final String ACCESS_TOKEN; }
@Test public void storesTheAccessTokenAfterUsingRefreshToken() throws Exception { profile.setAccessToken("expired_token!"); profile.setRefreshToken(REFRESH_TOKEN); oAuth2TokenExtractor.refreshAccessToken(parameters); assertThat(profile.getAccessToken(), is(ACCESS_TOKEN)); }