Search in sources :

Example 1 with OAuth1Version

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();
}
Also used : OAuthToken(org.springframework.social.oauth1.OAuthToken) OAuth1Parameters(org.springframework.social.oauth1.OAuth1Parameters) OAuth1Version(org.springframework.social.oauth1.OAuth1Version) OAuth1Operations(org.springframework.social.oauth1.OAuth1Operations)

Aggregations

OAuth1Operations (org.springframework.social.oauth1.OAuth1Operations)1 OAuth1Parameters (org.springframework.social.oauth1.OAuth1Parameters)1 OAuth1Version (org.springframework.social.oauth1.OAuth1Version)1 OAuthToken (org.springframework.social.oauth1.OAuthToken)1