/** * Construct a request message, send it to the service provider and get the * response. * * @return the response * @throws URISyntaxException * the given url isn't valid syntactically * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ @SuppressWarnings("rawtypes") public OAuthMessage invoke(OAuthAccessor accessor, String url, Collection<? extends Map.Entry> parameters) throws IOException, OAuthException, URISyntaxException { return invoke(accessor, null, url, parameters); }
/** * Get a fresh request token from the service provider. * * @param accessor * should contain a consumer that contains a non-null consumerKey * and consumerSecret. Also, * accessor.consumer.serviceProvider.requestTokenURL should be * the URL (determined by the service provider) for getting a * request token. * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ public void getRequestToken(OAuthAccessor accessor) throws IOException, OAuthException, URISyntaxException { getRequestToken(accessor, null); }
/** @deprecated */ public OAuthResponseMessage access(OAuthMessage request, ParameterStyle style) throws IOException { return access(request, style.getReplacement()); }
@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 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);
@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); } }
public static OAuthClient newOAuthClient(URI address) throws IOException { return new OAuthClient(new HttpClient4(newClientPool(address))); }
OAuthMessage message = client.getRequestTokenResponse(accessor, "GET", params); String rt = message.getParameter(OAUTH_TOKEN); if (rt == null || rt.length() == 0) {
arrayList.add(atRequest.getParameters().get(key)); OAuthMessage message = oauthClient.getAccessToken(accessor, "GET", OAuth.newList(arrayList.toArray(new String[arrayList.size()]))); HashMap m = whittleParameters(message); accessToken = new AccessTokenImpl(URI.create(message.getParameter(OAUTH_TOKEN)), URI.create(message.getParameter(OAUTH_TOKEN_SECRET)));
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();
/** * 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); }
/** @deprecated */ public OAuthMessage invoke(OAuthMessage request, ParameterStyle style) throws IOException, OAuthException { return invoke(request, style.getReplacement()); }
/** * Get a fresh request token from the service provider. * * @param accessor * should contain a consumer that contains a non-null consumerKey * and consumerSecret. Also, * accessor.consumer.serviceProvider.requestTokenURL should be * the URL (determined by the service provider) for getting a * request token. * @param httpMethod * typically OAuthMessage.POST or OAuthMessage.GET, or null to * use the default method. * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ public void getRequestToken(OAuthAccessor accessor, String httpMethod) throws IOException, OAuthException, URISyntaxException { getRequestToken(accessor, httpMethod, null); }
/** * Send a request message to the service provider and get the response. * * @return the response * @throws IOException * failed to communicate with the service provider * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ public OAuthMessage invoke(OAuthMessage request, net.oauth.ParameterStyle style) throws IOException, OAuthException { OAuthResponseMessage response = access(request, style); if ((response.getHttpResponse().getStatusCode() / 100) != 2) { throw response.toOAuthProblemException(); } return response; }
OAuthMessage message = client.invoke(request, ParameterStyle.AUTHORIZATION_HEADER);
OAuthClient oAuthClient = new OAuthClient(new HttpClient4()); try { oAuthClient.getRequestToken(accessor); } catch (IOException e) { e.printStackTrace(); } catch (OAuthException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); }
/** * Construct a request message, send it to the service provider and get the * response. * * @param httpMethod * the HTTP request method, or null to use the default method * @return the response * @throws URISyntaxException * the given url isn't valid syntactically * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ @SuppressWarnings("rawtypes") public OAuthMessage invoke(OAuthAccessor accessor, String httpMethod, String url, Collection<? extends Map.Entry> parameters) throws IOException, OAuthException, URISyntaxException { OAuthMessage request = accessor.newRequestMessage(httpMethod, url, parameters); Object accepted = accessor.consumer.getProperty(OAuthConsumer.ACCEPT_ENCODING); if (accepted != null) { request.getHeaders().add(new OAuth.Parameter(HttpMessage.ACCEPT_ENCODING, accepted.toString())); } Object ps = accessor.consumer.getProperty(PARAMETER_STYLE); net.oauth.ParameterStyle style = (ps == null) ? net.oauth.ParameterStyle.BODY : Enum.valueOf(net.oauth.ParameterStyle.class, ps.toString()); return invoke(request, style); }
/** * Applies for a request token from the service provider. * * @return the request token. */ private String getAndStoreRequestToken() { // Get the request token. try { oauthClient.getRequestToken(accessor); } catch (IOException e) { LOG.severe("Could not reach service provider to get request token: " + e); } catch (OAuthException e) { LOG.severe("Unable to fetch request token. Authentication error: " + e); } catch (URISyntaxException e) { LOG.severe("Unable to fetch request token. Invalid url: " + e); } // Store request token in Datastore via a tokenData object. String requestToken = accessor.requestToken; storeUserProfile(new OAuthUser(userRecordKey, requestToken)); return accessor.requestToken; }
OAuthMessage response = invoke(accessor, httpMethod, accessor.consumer.serviceProvider.requestTokenURL, parameters); accessor.requestToken = response.getParameter(OAuth.OAUTH_TOKEN);