use of org.springframework.social.oauth1.OAuth1Parameters in project syndesis by syndesisio.
the class OAuth1CredentialProvider method prepare.
@Override
public CredentialFlowState prepare(final String connectorId, final URI baseUrl, final URI returnUrl) {
final OAuth1CredentialFlowState.Builder flowState = new OAuth1CredentialFlowState.Builder().returnUrl(returnUrl).providerId(id);
final OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();
final OAuth1Parameters parameters = new OAuth1Parameters();
final String stateKey = UUID.randomUUID().toString();
flowState.key(stateKey);
final OAuthToken oAuthToken;
final OAuth1Version oAuthVersion = oauthOperations.getVersion();
if (oAuthVersion == OAuth1Version.CORE_10) {
parameters.setCallbackUrl(callbackUrlFor(baseUrl, EMPTY));
oAuthToken = oauthOperations.fetchRequestToken(null, null);
} else if (oAuthVersion == OAuth1Version.CORE_10_REVISION_A) {
oAuthToken = oauthOperations.fetchRequestToken(callbackUrlFor(baseUrl, EMPTY), null);
} else {
throw new IllegalStateException("Unsupported OAuth 1 version: " + oAuthVersion);
}
flowState.token(oAuthToken);
final String redirectUrl = oauthOperations.buildAuthorizeUrl(oAuthToken.getValue(), parameters);
flowState.redirectUrl(redirectUrl);
flowState.connectorId(connectorId);
return flowState.build();
}
use of org.springframework.social.oauth1.OAuth1Parameters in project syndesis by syndesisio.
the class CredentialsTest method shouldAcquireOAuth1aCredentials.
@Test
public void shouldAcquireOAuth1aCredentials() {
final OAuth1ConnectionFactory<?> oauth1 = mock(OAuth1ConnectionFactory.class);
@SuppressWarnings("unchecked") final Applicator<OAuthToken> applicator = mock(Applicator.class);
when(locator.providerWithId("providerId")).thenReturn(new OAuth1CredentialProvider<>("providerId", oauth1, applicator));
final OAuth1Operations operations = mock(OAuth1Operations.class);
when(oauth1.getOAuthOperations()).thenReturn(operations);
when(operations.getVersion()).thenReturn(OAuth1Version.CORE_10_REVISION_A);
final OAuthToken token = new OAuthToken("value", "secret");
when(operations.fetchRequestToken("https://syndesis.io/api/v1/credentials/callback", null)).thenReturn(token);
final ArgumentCaptor<OAuth1Parameters> parameters = ArgumentCaptor.forClass(OAuth1Parameters.class);
when(operations.buildAuthorizeUrl(eq("value"), parameters.capture())).thenReturn("https://provider.io/oauth/authorize");
final AcquisitionFlow acquisition = credentials.acquire("providerId", URI.create("https://syndesis.io/api/v1/"), URI.create("https://syndesis.io/ui#state"));
final CredentialFlowState expectedFlowState = new OAuth1CredentialFlowState.Builder().providerId("providerId").redirectUrl("https://provider.io/oauth/authorize").returnUrl(URI.create("https://syndesis.io/ui#state")).token(token).build();
final AcquisitionFlow expected = new AcquisitionFlow.Builder().type(Type.OAUTH1).redirectUrl("https://provider.io/oauth/authorize").state(expectedFlowState).build();
assertThat(acquisition).isEqualToIgnoringGivenFields(expected, "state");
final Optional<CredentialFlowState> maybeState = acquisition.state();
assertThat(maybeState).isPresent();
final CredentialFlowState state = maybeState.get();
assertThat(state).isEqualToIgnoringGivenFields(expectedFlowState, "key");
assertThat(state.getKey()).isNotNull();
final OAuth1Parameters oAuth1Parameters = parameters.getValue();
assertThat(oAuth1Parameters.getCallbackUrl()).isNull();
}
use of org.springframework.social.oauth1.OAuth1Parameters in project syndesis by syndesisio.
the class CredentialsTest method shouldAcquireOAuth1Credentials.
@Test
public void shouldAcquireOAuth1Credentials() {
final OAuth1ConnectionFactory<?> oauth1 = mock(OAuth1ConnectionFactory.class);
@SuppressWarnings("unchecked") final Applicator<OAuthToken> applicator = mock(Applicator.class);
when(locator.providerWithId("providerId")).thenReturn(new OAuth1CredentialProvider<>("providerId", oauth1, applicator));
final OAuth1Operations operations = mock(OAuth1Operations.class);
when(oauth1.getOAuthOperations()).thenReturn(operations);
when(operations.getVersion()).thenReturn(OAuth1Version.CORE_10);
final OAuthToken token = new OAuthToken("value", "secret");
when(operations.fetchRequestToken(null, null)).thenReturn(token);
final ArgumentCaptor<OAuth1Parameters> parameters = ArgumentCaptor.forClass(OAuth1Parameters.class);
when(operations.buildAuthorizeUrl(eq("value"), parameters.capture())).thenReturn("https://provider.io/oauth/authorize");
final AcquisitionFlow acquisition = credentials.acquire("providerId", URI.create("https://syndesis.io/api/v1/"), URI.create("/ui#state"));
final CredentialFlowState expectedFlowState = new OAuth1CredentialFlowState.Builder().providerId("providerId").redirectUrl("https://provider.io/oauth/authorize").returnUrl(URI.create("/ui#state")).token(token).build();
final AcquisitionFlow expected = new AcquisitionFlow.Builder().type(Type.OAUTH1).redirectUrl("https://provider.io/oauth/authorize").state(expectedFlowState).build();
assertThat(acquisition).isEqualToIgnoringGivenFields(expected, "state");
final Optional<CredentialFlowState> maybeState = acquisition.state();
assertThat(maybeState).isPresent();
final CredentialFlowState state = maybeState.get();
assertThat(state).isEqualToIgnoringGivenFields(expectedFlowState, "key");
assertThat(state.getKey()).isNotNull();
final OAuth1Parameters oAuth1Parameters = parameters.getValue();
assertThat(oAuth1Parameters.getCallbackUrl()).isEqualTo("https://syndesis.io/api/v1/credentials/callback");
}
Aggregations