Search in sources :

Example 1 with AccessGrant

use of org.springframework.social.oauth2.AccessGrant in project spring-boot by spring-projects.

the class SpringSocialTokenServices method loadAuthentication.

@Override
public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException, InvalidTokenException {
    AccessGrant accessGrant = new AccessGrant(accessToken);
    Connection<?> connection = this.connectionFactory.createConnection(accessGrant);
    UserProfile user = connection.fetchUserProfile();
    return extractAuthentication(user);
}
Also used : UserProfile(org.springframework.social.connect.UserProfile) AccessGrant(org.springframework.social.oauth2.AccessGrant)

Example 2 with AccessGrant

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

the class OAuth2CredentialProvider method finish.

@Override
public CredentialFlowState finish(final CredentialFlowState givenFlowState, final URI baseUrl) {
    final OAuth2CredentialFlowState flowState = flowState(givenFlowState);
    final AccessGrant accessGrant = connectionFactory.getOAuthOperations().exchangeForAccess(flowState.getCode(), callbackUrlFor(baseUrl, EMPTY), null);
    return new OAuth2CredentialFlowState.Builder().createFrom(flowState).accessGrant(accessGrant).build();
}
Also used : AccessGrant(org.springframework.social.oauth2.AccessGrant)

Example 3 with AccessGrant

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

the class CredentialsTest method shouldFinishOAuth2Acquisition.

@Test
public void shouldFinishOAuth2Acquisition() {
    final OAuth2ConnectionFactory<?> oauth2 = mock(OAuth2ConnectionFactory.class);
    final OAuth2Applicator applicator = new OAuth2Applicator(properties);
    applicator.setAccessTokenProperty("accessTokenProperty");
    applicator.setClientIdProperty("clientIdProperty");
    applicator.setClientSecretProperty("clientSecretProperty");
    applicator.setRefreshTokenProperty("refreshTokenProperty");
    when(locator.providerWithId("providerId")).thenReturn(new OAuth2CredentialProvider<>("providerId", oauth2, applicator));
    final OAuth2Operations operations = mock(OAuth2Operations.class);
    when(oauth2.getOAuthOperations()).thenReturn(operations);
    final AccessGrant accessGrant = new AccessGrant("accessToken", "scope", "refreshToken", 1L);
    when(operations.exchangeForAccess("code", "https://syndesis.io/api/v1/credentials/callback", null)).thenReturn(accessGrant);
    final CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder().providerId("providerId").returnUrl(URI.create("/ui#state")).code("code").state("state").build();
    final CredentialFlowState finalFlowState = credentials.finishAcquisition(flowState, URI.create("https://syndesis.io/api/v1/"));
    assertThat(finalFlowState).isEqualTo(new OAuth2CredentialFlowState.Builder().createFrom(flowState).accessGrant(accessGrant).build());
}
Also used : AccessGrant(org.springframework.social.oauth2.AccessGrant) OAuth2Operations(org.springframework.social.oauth2.OAuth2Operations) Test(org.junit.Test)

Example 4 with AccessGrant

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

the class SalesforceApplicatorTest method shouldApplyAdditionalProperties.

@Test
public void shouldApplyAdditionalProperties() {
    final SalesforceProperties properties = new SalesforceProperties();
    properties.setAppId("appId");
    properties.setAppSecret("appSecret");
    final AccessGrant accessGrant = new AccessGrant("accessToken", "scope", "refreshToken", 1L);
    final SalesforceConnectionFactory salesforce = mock(SalesforceConnectionFactory.class);
    @SuppressWarnings("unchecked") final org.springframework.social.connect.Connection<Salesforce> salesforceConnection = mock(org.springframework.social.connect.Connection.class);
    final Salesforce salesforceApi = mock(Salesforce.class);
    when(salesforceConnection.getApi()).thenReturn(salesforceApi);
    when(salesforceApi.getInstanceUrl()).thenReturn("https://instance.salesforce.com");
    when(salesforce.createConnection(accessGrant)).thenReturn(salesforceConnection);
    final Connection.Builder mutableConnection = new Connection.Builder();
    final SalesforceApplicator applicator = new SalesforceApplicator(salesforce, properties);
    applicator.additionalApplication(mutableConnection, accessGrant);
    assertThat(mutableConnection.build().getConfiguredProperties()).containsExactly(entry("instanceUrl", "https://instance.salesforce.com"));
}
Also used : AccessGrant(org.springframework.social.oauth2.AccessGrant) Connection(io.syndesis.common.model.connection.Connection) SalesforceConnectionFactory(org.springframework.social.salesforce.connect.SalesforceConnectionFactory) SalesforceApplicator(io.syndesis.server.credential.salesforce.SalesforceConfiguration.SalesforceApplicator) Salesforce(org.springframework.social.salesforce.api.Salesforce) Test(org.junit.Test)

Example 5 with AccessGrant

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

the class CredentialITCase method shouldApplyOAuthPropertiesToNewlyCreatedConnections.

@Test
public void shouldApplyOAuthPropertiesToNewlyCreatedConnections() {
    final OAuth2CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder().providerId("test-provider").key("key").accessGrant(new AccessGrant("token")).build();
    final HttpHeaders cookies = persistAsCookie(flowState);
    final Connection newConnection = new Connection.Builder().name("Test connection").connectorId("http").build();
    final ResponseEntity<Connection> connectionResponse = http(HttpMethod.POST, "/api/v1/connections", newConnection, Connection.class, tokenRule.validToken(), cookies, HttpStatus.OK);
    assertThat(connectionResponse.hasBody()).as("Should contain created connection").isTrue();
    final Connection createdConnection = connectionResponse.getBody();
    assertThat(createdConnection.isDerived()).isTrue();
    assertThat(createdConnection.getConfiguredProperties()).containsOnly(entry("accessToken", "token"), entry("clientId", "appId"), entry("clientSecret", "appSecret"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) AccessGrant(org.springframework.social.oauth2.AccessGrant) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Connection(io.syndesis.common.model.connection.Connection) OAuth2CredentialFlowState(io.syndesis.server.credential.OAuth2CredentialFlowState) Test(org.junit.Test)

Aggregations

AccessGrant (org.springframework.social.oauth2.AccessGrant)9 Test (org.junit.Test)6 Connection (io.syndesis.common.model.connection.Connection)3 OAuth2Operations (org.springframework.social.oauth2.OAuth2Operations)3 OAuth2CredentialFlowState (io.syndesis.server.credential.OAuth2CredentialFlowState)2 HttpHeaders (org.springframework.http.HttpHeaders)2 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)2 CredentialProvider (io.syndesis.server.credential.CredentialProvider)1 OAuth2Applicator (io.syndesis.server.credential.OAuth2Applicator)1 OAuth2CredentialProvider (io.syndesis.server.credential.OAuth2CredentialProvider)1 SalesforceApplicator (io.syndesis.server.credential.salesforce.SalesforceConfiguration.SalesforceApplicator)1 SocialProperties (org.springframework.boot.autoconfigure.social.SocialProperties)1 UserProfile (org.springframework.social.connect.UserProfile)1 OAuth2Parameters (org.springframework.social.oauth2.OAuth2Parameters)1 OAuth2Template (org.springframework.social.oauth2.OAuth2Template)1 Salesforce (org.springframework.social.salesforce.api.Salesforce)1 SalesforceConnectionFactory (org.springframework.social.salesforce.connect.SalesforceConnectionFactory)1 MultiValueMap (org.springframework.util.MultiValueMap)1