public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, MultiValueMap<String, String> additionalParameters) { Map<String, String> tokenParameters = new HashMap<String, String>(2, 1); tokenParameters.put("oauth_token", requestToken.getValue()); if (version == OAuth1Version.CORE_10_REVISION_A) { tokenParameters.put("oauth_verifier", requestToken.getVerifier()); } return exchangeForToken(accessTokenUrl, tokenParameters, additionalParameters, requestToken.getSecret()); }
/** * Complete the connection to the OAuth1 provider. * @param connectionFactory the service provider's connection factory e.g. FacebookConnectionFactory * @param request the current web request * @return a new connection to the service provider */ public Connection<?> completeConnection(OAuth1ConnectionFactory<?> connectionFactory, NativeWebRequest request) { String verifier = request.getParameter("oauth_verifier"); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(extractCachedRequestToken(request), verifier); OAuthToken accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(requestToken, null); return connectionFactory.createConnection(accessToken); }
@Override public CredentialFlowState finish(final CredentialFlowState givenFlowState, final URI baseUrl) { final OAuth1CredentialFlowState flowState = flowState(givenFlowState); final AuthorizedRequestToken requestToken = new AuthorizedRequestToken(flowState.getToken(), flowState.getVerifier()); final OAuthToken accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(requestToken, null); return new OAuth1CredentialFlowState.Builder().createFrom(flowState).accessToken(accessToken).build(); }
public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, MultiValueMap<String, String> additionalParameters) { Map<String, String> tokenParameters = new HashMap<String, String>(2, 1); tokenParameters.put("oauth_token", requestToken.getValue()); if (version == OAuth1Version.CORE_10_REVISION_A) { tokenParameters.put("oauth_verifier", requestToken.getVerifier()); } return exchangeForToken(accessTokenUrl, tokenParameters, additionalParameters, requestToken.getSecret()); }
@Override public CredentialFlowState finish(final CredentialFlowState givenFlowState, final URI baseUrl) { final OAuth1CredentialFlowState flowState = flowState(givenFlowState); final AuthorizedRequestToken requestToken = new AuthorizedRequestToken(flowState.getToken(), flowState.getVerifier()); final OAuthToken accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(requestToken, null); return new OAuth1CredentialFlowState.Builder().createFrom(flowState).accessToken(accessToken).build(); }
@Override public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, MultiValueMap<String, String> additionalParameters) { try { OAuthAccessor accessor = getAccessor(); OAuthClient client = new OAuthClient(new HttpClient4()); accessor.requestToken = requestToken.getValue(); accessor.tokenSecret = requestToken.getSecret(); OAuthMessage message = client.getAccessToken(accessor, "POST", Stream.of(new OAuth.Parameter(OAuth.OAUTH_VERIFIER, requestToken.getVerifier())).collect(Collectors.toList())); return new OAuthToken(message.getToken(), requestToken.getSecret()); } catch (Exception e) { throw new RestClientException("Failed to swap request token with access token", e); } }
return null; OAuthToken accessToken = getConnectionFactory().getOAuthOperations().exchangeForAccessToken(new AuthorizedRequestToken(requestToken, verifier), null);
@Test public void shouldFinishOAuth1Acquisition() { final OAuthToken token = new OAuthToken("value", "secret"); final OAuth1ConnectionFactory<?> oauth1 = mock(OAuth1ConnectionFactory.class); final OAuth1Applicator applicator = new OAuth1Applicator(properties); when(locator.providerWithId("providerId")) .thenReturn(new OAuth1CredentialProvider<>("providerId", oauth1, applicator)); final OAuth1Operations operations = mock(OAuth1Operations.class); when(oauth1.getOAuthOperations()).thenReturn(operations); final ArgumentCaptor<AuthorizedRequestToken> requestToken = ArgumentCaptor .forClass(AuthorizedRequestToken.class); final OAuthToken accessToken = new OAuthToken("tokenValue", "tokenSecret"); @SuppressWarnings({"unchecked", "rawtypes"}) final Class<MultiValueMap<String, String>> multimapType = (Class) MultiValueMap.class; when(operations.exchangeForAccessToken(requestToken.capture(), isNull(multimapType))).thenReturn(accessToken); applicator.setAccessTokenSecretProperty("accessTokenSecretProperty"); applicator.setAccessTokenValueProperty("accessTokenValueProperty"); applicator.setConsumerKeyProperty("consumerKeyProperty"); applicator.setConsumerSecretProperty("consumerSecretProperty"); final CredentialFlowState flowState = new OAuth1CredentialFlowState.Builder().providerId("providerId") .token(token).returnUrl(URI.create("/ui#state")).verifier("verifier").build(); final CredentialFlowState finalFlowState = credentials.finishAcquisition(flowState, URI.create("https://www.example.com")); final AuthorizedRequestToken capturedRequestToken = requestToken.getValue(); assertThat(capturedRequestToken.getValue()).isEqualTo("value"); assertThat(capturedRequestToken.getSecret()).isEqualTo("secret"); assertThat(capturedRequestToken.getVerifier()).isEqualTo("verifier"); assertThat(finalFlowState) .isEqualTo(new OAuth1CredentialFlowState.Builder().createFrom(flowState).accessToken(accessToken).build()); }
return null; OAuthToken accessToken = getConnectionFactory().getOAuthOperations().exchangeForAccessToken(new AuthorizedRequestToken(requestToken, verifier), null);