Search in sources :

Example 1 with AuthorizedRequestToken

use of org.springframework.social.oauth1.AuthorizedRequestToken in project syndesis by syndesisio.

the class CredentialsTest method shouldFinishOAuth1Acquisition.

@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());
}
Also used : OAuthToken(org.springframework.social.oauth1.OAuthToken) AuthorizedRequestToken(org.springframework.social.oauth1.AuthorizedRequestToken) OAuth1Operations(org.springframework.social.oauth1.OAuth1Operations) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test)

Example 2 with AuthorizedRequestToken

use of org.springframework.social.oauth1.AuthorizedRequestToken in project syndesis by syndesisio.

the class OAuth1CredentialProvider method finish.

@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();
}
Also used : OAuthToken(org.springframework.social.oauth1.OAuthToken) AuthorizedRequestToken(org.springframework.social.oauth1.AuthorizedRequestToken)

Aggregations

AuthorizedRequestToken (org.springframework.social.oauth1.AuthorizedRequestToken)2 OAuthToken (org.springframework.social.oauth1.OAuthToken)2 Test (org.junit.Test)1 OAuth1Operations (org.springframework.social.oauth1.OAuth1Operations)1 MultiValueMap (org.springframework.util.MultiValueMap)1