Java Code Examples for oauth.signpost.OAuthConsumer#sign()
The following examples show how to use
oauth.signpost.OAuthConsumer#sign() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BurpExtender.java From burp-oauth with MIT License | 6 votes |
@Override public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequestResponse messageInfo) { if (messageIsRequest && shouldSign(messageInfo)) { HttpRequest req = new BurpHttpRequestWrapper(messageInfo); OAuthConsumer consumer = new DefaultOAuthConsumer( OAuthConfig.getConsumerKey(), OAuthConfig.getConsumerSecret()); consumer.setTokenWithSecret(OAuthConfig.getToken(), OAuthConfig.getTokenSecret()); try { consumer.sign(req); } catch (OAuthException oae) { oae.printStackTrace(); } } }
Example 2
Source File: RestTask.java From android-discourse with Apache License 2.0 | 5 votes |
@Override protected RestResult doInBackground(String... args) { try { request = createRequest(); if (isCancelled()) throw new InterruptedException(); OAuthConsumer consumer = Session.getInstance().getOAuthConsumer(); if (consumer != null) { AccessToken accessToken = Session.getInstance().getAccessToken(); if (accessToken != null) { consumer.setTokenWithSecret(accessToken.getKey(), accessToken.getSecret()); } consumer.sign(request); } request.setHeader("Accept-Language", Locale.getDefault().getLanguage()); request.setHeader("API-Client", String.format("uservoice-android-%s", UserVoice.getVersion())); AndroidHttpClient client = AndroidHttpClient.newInstance(String.format("uservoice-android-%s", UserVoice.getVersion()), Session.getInstance().getContext()); if (isCancelled()) throw new InterruptedException(); // TODO it would be nice to find a way to abort the request on cancellation HttpResponse response = client.execute(request); if (isCancelled()) throw new InterruptedException(); HttpEntity responseEntity = response.getEntity(); StatusLine responseStatus = response.getStatusLine(); int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0; String body = responseEntity != null ? EntityUtils.toString(responseEntity) : null; client.close(); if (isCancelled()) throw new InterruptedException(); return new RestResult(statusCode, new JSONObject(body)); } catch (Exception e) { return new RestResult(e); } }
Example 3
Source File: WSUrlFetch.java From restcommander with Apache License 2.0 | 5 votes |
private HttpURLConnection prepare(URL url, String method) { if (this.username != null && this.password != null && this.scheme != null) { String authString = null; switch (this.scheme) { case BASIC: authString = basicAuthHeader(); break; default: throw new RuntimeException("Scheme " + this.scheme + " not supported by the UrlFetch WS backend."); } this.headers.put("Authorization", authString); } try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(method); connection.setDoInput(true); connection.setInstanceFollowRedirects(this.followRedirects); connection.setReadTimeout(this.timeout * 1000); for (String key: this.headers.keySet()) { connection.setRequestProperty(key, headers.get(key)); } checkFileBody(connection); if (this.oauthToken != null && this.oauthSecret != null) { OAuthConsumer consumer = new DefaultOAuthConsumer(oauthInfo.consumerKey, oauthInfo.consumerSecret); consumer.setTokenWithSecret(oauthToken, oauthSecret); consumer.sign(connection); } return connection; } catch(Exception e) { throw new RuntimeException(e); } }
Example 4
Source File: OAuthTest.java From burp-oauth with MIT License | 5 votes |
@Test public void testSignature() throws Exception { HttpRequest hr = reqWrapForTestInput(1); OAuthConsumer consumer = new DefaultOAuthConsumer("1234", "5678"); consumer.setTokenWithSecret("9ABC", "DEF0"); consumer.sign(hr); }