Search in sources :

Example 1 with OAuth2Applicator

use of io.syndesis.server.credential.OAuth2Applicator in project syndesis by syndesisio.

the class OAuth2CredentialProviderFactory method create.

@Override
public CredentialProvider create(final SocialProperties properties) {
    final OAuth2ConnectorProperties oauth2Properties = (OAuth2ConnectorProperties) properties;
    final String appId = oauth2Properties.getAppId();
    final String appSecret = oauth2Properties.getAppSecret();
    final String authorizationUrl = oauth2Properties.getAuthorizationUrl();
    final String authenticationUrl = oauth2Properties.getAuthenticationUrl();
    final String accessTokenUrl = oauth2Properties.getAccessTokenUrl();
    final boolean useParametersForClientCredentials = oauth2Properties.isUseParametersForClientCredentials();
    final TokenStrategy tokenStrategy = oauth2Properties.getTokenStrategy();
    final String scope = oauth2Properties.getScope();
    final OAuth2ServiceProvider<RestOperations> serviceProvider = new GenericOAuth2ServiceProvider(appId, appSecret, authorizationUrl, authenticationUrl, accessTokenUrl, useParametersForClientCredentials, tokenStrategy);
    final OAuth2ConnectionFactory<RestOperations> connectionFactory = new OAuth2ConnectionFactory<>("oauth2", serviceProvider, null);
    connectionFactory.setScope(scope);
    final OAuth2Applicator applicator = new OAuth2Applicator(properties);
    applicator.setAccessTokenProperty("accessToken");
    return new OAuth2CredentialProvider<>("oauth2", connectionFactory, applicator);
}
Also used : OAuth2Applicator(io.syndesis.server.credential.OAuth2Applicator) OAuth2ConnectorProperties(io.syndesis.server.credential.OAuth2ConnectorProperties) OAuth2ConnectionFactory(org.springframework.social.connect.support.OAuth2ConnectionFactory) OAuth2CredentialProvider(io.syndesis.server.credential.OAuth2CredentialProvider) TokenStrategy(org.springframework.social.oauth2.TokenStrategy) RestOperations(org.springframework.web.client.RestOperations) GenericOAuth2ServiceProvider(org.springframework.social.oauth2.GenericOAuth2ServiceProvider)

Example 2 with OAuth2Applicator

use of io.syndesis.server.credential.OAuth2Applicator 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)

Aggregations

OAuth2Applicator (io.syndesis.server.credential.OAuth2Applicator)2 OAuth2CredentialProvider (io.syndesis.server.credential.OAuth2CredentialProvider)2 CredentialProvider (io.syndesis.server.credential.CredentialProvider)1 OAuth2ConnectorProperties (io.syndesis.server.credential.OAuth2ConnectorProperties)1 OAuth2ConnectionFactory (org.springframework.social.connect.support.OAuth2ConnectionFactory)1 AccessGrant (org.springframework.social.oauth2.AccessGrant)1 GenericOAuth2ServiceProvider (org.springframework.social.oauth2.GenericOAuth2ServiceProvider)1 OAuth2Operations (org.springframework.social.oauth2.OAuth2Operations)1 OAuth2Template (org.springframework.social.oauth2.OAuth2Template)1 TokenStrategy (org.springframework.social.oauth2.TokenStrategy)1 MultiValueMap (org.springframework.util.MultiValueMap)1 RestOperations (org.springframework.web.client.RestOperations)1