/** * Creates an {@link OAuthToken} given the response from the request token or access token exchange with the provider. * May be overridden to create a custom {@link OAuthToken}. * @param tokenValue the token value received from the provider. * @param tokenSecret the token secret received from the provider. * @param response all parameters from the response received in the request/access token exchange. * @return an {@link OAuthToken} */ protected OAuthToken createOAuthToken(String tokenValue, String tokenSecret, MultiValueMap<String, String> response) { return new OAuthToken(tokenValue, tokenSecret); }
/** * The request token value. * @return the token's value */ public String getValue() { return requestToken.getValue(); }
/** * The request token secret. * @return the token's secret */ public String getSecret() { return requestToken.getSecret(); }
/** * Create a OAuth1-based Connection from the access token response returned after {@link #getOAuthOperations() completing the OAuth1 flow}. * @param accessToken the access token * @return the new service provider connection * @see OAuth1Operations#exchangeForAccessToken(org.springframework.social.oauth1.AuthorizedRequestToken, org.springframework.util.MultiValueMap) */ public Connection<A> createConnection(OAuthToken accessToken) { String providerUserId = extractProviderUserId(accessToken); return new OAuth1Connection<A>(getProviderId(), providerUserId, accessToken.getValue(), accessToken.getSecret(), getOAuth1ServiceProvider(), getApiAdapter()); }
/** * Create a OAuth1-based Connection from the access token response returned after {@link #getOAuthOperations() completing the OAuth1 flow}. * @param accessToken the access token * @return the new service provider connection * @see OAuth1Operations#exchangeForAccessToken(org.springframework.social.oauth1.AuthorizedRequestToken, org.springframework.util.MultiValueMap) */ public Connection<A> createConnection(OAuthToken accessToken) { String providerUserId = extractProviderUserId(accessToken); return new OAuth1Connection<A>(getProviderId(), providerUserId, accessToken.getValue(), accessToken.getSecret(), getOAuth1ServiceProvider(), getApiAdapter()); }
/** * Creates an {@link OAuthToken} given the response from the request token or access token exchange with the provider. * May be overridden to create a custom {@link OAuthToken}. * @param tokenValue the token value received from the provider. * @param tokenSecret the token secret received from the provider. * @param response all parameters from the response received in the request/access token exchange. * @return an {@link OAuthToken} */ protected OAuthToken createOAuthToken(String tokenValue, String tokenSecret, MultiValueMap<String, String> response) { return new OAuthToken(tokenValue, tokenSecret); }
@Override public Connection applyTo(final Connection connection, final OAuthToken token) { final Connection.Builder mutableConnection = new Connection.Builder().createFrom(connection) .lastUpdated(new Date()); Applicator.applyProperty(mutableConnection, accessTokenValueProperty, token.getValue()); Applicator.applyProperty(mutableConnection, accessTokenSecretProperty, token.getSecret()); Applicator.applyProperty(mutableConnection, consumerKeyProperty, consumerKey); Applicator.applyProperty(mutableConnection, consumerSecretProperty, consumerSecret); return mutableConnection.build(); }
/** * The request token value. * @return the token's value */ public String getValue() { return requestToken.getValue(); }
/** * The request token secret. * @return the token's secret */ public String getSecret() { return requestToken.getSecret(); }
@Override public OAuthToken convert(final Map<String, String> value) { return new OAuthToken(value.get("value"), value.get("secret")); }
@Override public Connection applyTo(final Connection connection, final OAuthToken token) { final Connection.Builder mutableConnection = new Connection.Builder().createFrom(connection) .lastUpdated(new Date()); Applicator.applyProperty(mutableConnection, accessTokenValueProperty, token.getValue()); Applicator.applyProperty(mutableConnection, accessTokenSecretProperty, token.getSecret()); Applicator.applyProperty(mutableConnection, consumerKeyProperty, consumerKey); Applicator.applyProperty(mutableConnection, consumerSecretProperty, consumerSecret); return mutableConnection.build(); }
params = OAuth1Parameters.NONE; throw new SocialAuthenticationRedirectException(ops.buildAuthenticateUrl(requestToken.getValue(), params)); } else {
@Override public OAuthToken convert(final Map<String, String> value) { return new OAuthToken(value.get("value"), value.get("secret")); }
params = OAuth1Parameters.NONE; throw new SocialAuthenticationRedirectException(ops.buildAuthenticateUrl(requestToken.getValue(), params)); } else {
@Override public OAuthToken deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final Map<String, String> values = new HashMap<>(); String fieldName; while ((fieldName = p.nextFieldName()) != null) { final String nextValue = p.nextTextValue(); values.put(fieldName, nextValue); } return new OAuthToken(values.get("value"), values.get("secret")); } }
@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(); }
@Override public OAuthToken deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final Map<String, String> values = new HashMap<>(); String fieldName; while ((fieldName = p.nextFieldName()) != null) { final String nextValue = p.nextTextValue(); values.put(fieldName, nextValue); } return new OAuthToken(values.get("value"), values.get("secret")); } }
@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(); }
@Override public OAuthToken fetchRequestToken(String callbackUrl, MultiValueMap<String, String> additionalParameters) { try { OAuthAccessor accessor = getAccessor(); OAuthClient oAuthClient = new OAuthClient(new HttpClient4()); List<OAuth.Parameter> callBack; if (callback == null || "".equals(callback)) { callBack = Collections.<OAuth.Parameter>emptyList(); } else { callBack = Stream.of(new OAuth.Parameter(OAuth.OAUTH_CALLBACK, callback)).collect(Collectors.toList()); } OAuthMessage message = oAuthClient.getRequestTokenResponse(accessor, "POST", callBack); return new OAuthToken(accessor.requestToken, accessor.tokenSecret); } catch (Exception e) { throw new RestClientException("Failed to obtain request token", e); } }
private String buildOAuth1Url(OAuth1ConnectionFactory<?> connectionFactory, NativeWebRequest request, MultiValueMap<String, String> additionalParameters) { OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations(); MultiValueMap<String, String> requestParameters = getRequestParameters(request); OAuth1Parameters parameters = getOAuth1Parameters(request, additionalParameters); parameters.putAll(requestParameters); if (oauthOperations.getVersion() == OAuth1Version.CORE_10) { parameters.setCallbackUrl(callbackUrl(request)); } OAuthToken requestToken = fetchRequestToken(request, requestParameters, oauthOperations); sessionStrategy.setAttribute(request, OAUTH_TOKEN_ATTRIBUTE, requestToken); return buildOAuth1Url(oauthOperations, requestToken.getValue(), parameters); }