public static OAuthClient newOAuthClient(URI address) throws IOException { return new OAuthClient(new HttpClient4(newClientPool(address))); }
@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); } }
logger.debug("Attempting to send OAuth message {}", lisResultMessage); final HttpClient4 httpClient4 = new HttpClient4(); final OAuthClient client = new OAuthClient(httpClient4); oauthResponseMessage = client.access(lisResultMessage, ParameterStyle.AUTHORIZATION_HEADER);
new SimpleEntry<String, String>(HttpMessage.CONTENT_TYPE, JSON_MIME_TYPE)); message.getHeaders().add(new SimpleEntry<String, String>("oauth_version", "1.0")); OAuthClient client = new OAuthClient(httpFetcher); responseStream = client.invoke(message, net.oauth.ParameterStyle.BODY).getBodyAsStream();
@Test public void testGetWebSudoProtectedResourcePermitsOAuthToByPassWebSudo() throws Exception { // setup the consumer first. setUpOAuthConsumer(); OAuthAccessor accessor = createAccessor(CONSUMER_KEY); OAuthClient client = new OAuthClient(new HttpClient4()); // make the request. OAuthMessage response = client.invoke(accessor, getResourceUri().toString(), ImmutableMap.of("oauth_token", "").entrySet()); // assert stuff assertEquals(HttpServletResponse.SC_OK, ((OAuthResponseMessage) response).getHttpResponse().getStatusCode()); assertEquals("hello", response.readBodyAsString()); }
@Override public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, MultiValueMap<String, String> additionalParameters) { try { OAuthAccessor accessor = getAccessor(); OAuthClient client = new OAuthClient(new HttpClient4()); accessor.requestToken = requestToken.getValue(); accessor.tokenSecret = requestToken.getSecret(); OAuthMessage message = client.getAccessToken(accessor, "POST", Stream.of(new OAuth.Parameter(OAuth.OAUTH_VERIFIER, requestToken.getVerifier())).collect(Collectors.toList())); return new OAuthToken(message.getToken(), requestToken.getSecret()); } catch (Exception e) { throw new RestClientException("Failed to swap request token with access token", e); } }
/** * Factory method. Initializes OAuthServiceProvider with necessary tokens and * urls. * * @param userRecordKey key consisting of user id and wave id. * @param consumerKey service provider OAuth consumer key. * @param consumerSecret service provider OAuth consumer secret. * @param requestTokenUrl url to get service provider request token. * @param authorizeUrl url to service provider authorize page. * @param callbackUrl url to callback page. * @param accessTokenUrl url to get service provider access token. * @return OAuthService instance. */ public static OAuthService newInstance(String userRecordKey, String consumerKey, String consumerSecret, String requestTokenUrl, String authorizeUrl, String callbackUrl, String accessTokenUrl) { OAuthServiceProvider provider = new OAuthServiceProvider(requestTokenUrl, authorizeUrl, accessTokenUrl); OAuthConsumer consumer = new OAuthConsumer(callbackUrl, consumerKey, consumerSecret, provider); OAuthAccessor accessor = new OAuthAccessor(consumer); OAuthClient client = new OAuthClient(new OpenSocialHttpClient()); PersistenceManagerFactory pmf = SingletonPersistenceManagerFactory.get(); return new OAuthServiceImpl(accessor, client, pmf, userRecordKey); }