use of org.springframework.social.oauth1.OAuth1Version in project syndesis by syndesisio.
the class OAuth1CredentialProvider method prepare.
@Override
public CredentialFlowState prepare(final String connectorId, final URI baseUrl, final URI returnUrl) {
final OAuth1CredentialFlowState.Builder flowState = new OAuth1CredentialFlowState.Builder().returnUrl(returnUrl).providerId(id);
final OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();
final OAuth1Parameters parameters = new OAuth1Parameters();
final String stateKey = UUID.randomUUID().toString();
flowState.key(stateKey);
final OAuthToken oAuthToken;
final OAuth1Version oAuthVersion = oauthOperations.getVersion();
if (oAuthVersion == OAuth1Version.CORE_10) {
parameters.setCallbackUrl(callbackUrlFor(baseUrl, EMPTY));
oAuthToken = oauthOperations.fetchRequestToken(null, null);
} else if (oAuthVersion == OAuth1Version.CORE_10_REVISION_A) {
oAuthToken = oauthOperations.fetchRequestToken(callbackUrlFor(baseUrl, EMPTY), null);
} else {
throw new IllegalStateException("Unsupported OAuth 1 version: " + oAuthVersion);
}
flowState.token(oAuthToken);
final String redirectUrl = oauthOperations.buildAuthorizeUrl(oAuthToken.getValue(), parameters);
flowState.redirectUrl(redirectUrl);
flowState.connectorId(connectorId);
return flowState.build();
}
Aggregations