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);
}
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();
}
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());
}
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"));
}
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"));
}
Aggregations