Search in sources :

Example 1 with OAuth2Template

use of org.springframework.social.oauth2.OAuth2Template 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;
}
Also used : OAuth2Applicator(io.syndesis.server.credential.OAuth2Applicator) OAuth2CredentialProvider(io.syndesis.server.credential.OAuth2CredentialProvider) OAuth2Template(org.springframework.social.oauth2.OAuth2Template) AccessGrant(org.springframework.social.oauth2.AccessGrant) OAuth2CredentialProvider(io.syndesis.server.credential.OAuth2CredentialProvider) CredentialProvider(io.syndesis.server.credential.CredentialProvider) OAuth2Operations(org.springframework.social.oauth2.OAuth2Operations) MultiValueMap(org.springframework.util.MultiValueMap)

Example 2 with OAuth2Template

use of org.springframework.social.oauth2.OAuth2Template in project syndesis by syndesisio.

the class SalesforceCredentialProviderFactory method createConnectionFactory.

static SalesforceConnectionFactory createConnectionFactory(final SocialProperties salesforceProperties) {
    final SalesforceConnectionFactory salesforce = new SalesforceConnectionFactory(salesforceProperties.getAppId(), salesforceProperties.getAppSecret());
    final OAuth2Template oAuthOperations = (OAuth2Template) salesforce.getOAuthOperations();
    // Salesforce requires OAuth client id and secret on the OAuth request
    oAuthOperations.setUseParametersForClientAuthentication(true);
    return salesforce;
}
Also used : OAuth2Template(org.springframework.social.oauth2.OAuth2Template) SalesforceConnectionFactory(org.springframework.social.salesforce.connect.SalesforceConnectionFactory)

Aggregations

OAuth2Template (org.springframework.social.oauth2.OAuth2Template)2 CredentialProvider (io.syndesis.server.credential.CredentialProvider)1 OAuth2Applicator (io.syndesis.server.credential.OAuth2Applicator)1 OAuth2CredentialProvider (io.syndesis.server.credential.OAuth2CredentialProvider)1 AccessGrant (org.springframework.social.oauth2.AccessGrant)1 OAuth2Operations (org.springframework.social.oauth2.OAuth2Operations)1 SalesforceConnectionFactory (org.springframework.social.salesforce.connect.SalesforceConnectionFactory)1 MultiValueMap (org.springframework.util.MultiValueMap)1