use of io.syndesis.server.credential.CredentialProvider in project syndesis by syndesisio.
the class TestCredentialProviderFactory method create.
@Override
public CredentialProvider create(final SocialProperties properties) {
@SuppressWarnings("unchecked") final OAuth2ConnectionFactory<Object> connectionFactory = mock(OAuth2ConnectionFactory.class);
when(connectionFactory.generateState()).thenReturn("test-state");
properties.setAppId("appId");
properties.setAppSecret("appSecret");
final OAuth2Applicator applicator = new OAuth2Applicator(properties);
applicator.setAccessTokenProperty("accessToken");
applicator.setClientIdProperty("clientId");
applicator.setClientSecretProperty("clientSecret");
applicator.setRefreshTokenProperty("refreshToken");
final CredentialProvider credentialProvider = new OAuth2CredentialProvider<>("test-provider", connectionFactory, applicator);
@SuppressWarnings({ "unchecked", "rawtypes" }) final Class<MultiValueMap<String, String>> additionalParametersType = (Class) MultiValueMap.class;
final OAuth2Operations operations = spy(new OAuth2Template("testClientId", "testClientSecret", "https://test/oauth2/authorize", "https://test/oauth2/token"));
doReturn(new AccessGrant("token")).when(operations).exchangeForAccess(Matchers.anyString(), Matchers.anyString(), Matchers.any(additionalParametersType));
when(connectionFactory.getOAuthOperations()).thenReturn(operations);
return credentialProvider;
}
use of io.syndesis.server.credential.CredentialProvider in project syndesis by syndesisio.
the class SetupITCase method updateOauthApp.
@Test
public void updateOauthApp() {
// Validate initial state assumptions.
getOauthApps();
OAuthAppHandler.OAuthApp twitter = new OAuthAppHandler.OAuthApp();
twitter.clientId = "test-id";
twitter.clientSecret = "test-secret";
http(HttpMethod.PUT, "/api/v1/setup/oauth-apps/twitter", twitter, null, tokenRule.validToken(), HttpStatus.NO_CONTENT);
ResponseEntity<OAuthAppHandler.OAuthApp[]> result = get("/api/v1/setup/oauth-apps", OAuthAppHandler.OAuthApp[].class);
List<OAuthAppHandler.OAuthApp> apps = Arrays.asList(result.getBody());
assertThat(apps.size()).isEqualTo(2);
twitter = apps.stream().filter(x -> "twitter".equals(x.id)).findFirst().get();
assertThat(twitter.id).isEqualTo("twitter");
assertThat(twitter.name).isEqualTo("Twitter");
assertThat(twitter.icon).isEqualTo("fa-twitter");
assertThat(twitter.clientId).isEqualTo("test-id");
assertThat(twitter.clientSecret).isEqualTo("test-secret");
// Now that we have configured the app, we should be able to create the
// connection factory.
// The connection factory is setup async so we might need to wait a little bit
// for it to register.
given().ignoreExceptions().await().atMost(10, SECONDS).pollInterval(1, SECONDS).until(() -> {
final CredentialProvider twitterCredentialProvider = locator.providerWithId("twitter");
// preparing is something we could not do with a `null` ConnectionFactory
assertThat(twitterCredentialProvider).isNotNull().isInstanceOfSatisfying(OAuth1CredentialProvider.class, p -> {
final Connection connection = new Connection.Builder().build();
final CredentialFlowState flowState = new OAuth1CredentialFlowState.Builder().accessToken(new OAuthToken("value", "secret")).connectorId("connectorId").build();
final Connection appliedTo = p.applyTo(connection, flowState);
// test that the updated values are used
assertThat(appliedTo.getConfiguredProperties()).contains(entry("consumerKey", "test-id"), entry("consumerSecret", "test-secret"));
});
return true;
});
}
Aggregations