use of oauth.signpost.commonshttp.CommonsHttpOAuthConsumer in project ArTEMiS by ls1intum.
the class PatchedIMSPOXRequest method buildReplaceResult.
public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid, String score, String resultData, Boolean isUrl) throws IOException, OAuthException, GeneralSecurityException {
String dataXml = "";
if (resultData != null) {
String format = isUrl ? resultDataUrl : resultDataText;
dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData));
}
String xml = String.format(patchedReplaceResultMessage, StringEscapeUtils.escapeXml(sourcedid), StringEscapeUtils.escapeXml(score), dataXml);
HttpParameters parameters = new HttpParameters();
String hash = getBodyHash(xml);
parameters.put("oauth_body_hash", URLEncoder.encode(hash, "UTF-8"));
CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
HttpPost request = new HttpPost(url);
request.setHeader("Content-Type", "application/xml");
request.setEntity(new StringEntity(xml, "UTF-8"));
signer.setAdditionalParameters(parameters);
signer.sign(request);
return request;
}
use of oauth.signpost.commonshttp.CommonsHttpOAuthConsumer in project signpost-examples by mttkay.
the class FireEagleMain method main.
public static void main(String[] args) throws Exception {
OAuthConsumer consumer = new CommonsHttpOAuthConsumer("2qnk0OzpuzzU", "Ctp1QtFbtSaFhOJbOLMCUPio9c75zIaG");
OAuthProvider provider = new CommonsHttpOAuthProvider("https://fireeagle.yahooapis.com/oauth/request_token", "https://fireeagle.yahooapis.com/oauth/access_token", "https://fireeagle.yahoo.net/oauth/authorize");
System.out.println("Fetching request token from Fire Eagle...");
// we do not support callbacks, thus pass OOB
String authUrl = provider.retrieveRequestToken(consumer, "http://www.example.com");
System.out.println("Request token: " + consumer.getToken());
System.out.println("Token secret: " + consumer.getTokenSecret());
System.out.println("Now visit:\n" + authUrl + "\n... and grant this app authorization");
System.out.println("Enter the verification code and hit ENTER when you're done");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String code = br.readLine();
System.out.println("Fetching access token from Fire Eagle...");
provider.retrieveAccessToken(consumer, code);
System.out.println("Access token: " + consumer.getToken());
System.out.println("Token secret: " + consumer.getTokenSecret());
HttpPost request = new HttpPost("https://fireeagle.yahooapis.com/api/0.1/update");
StringEntity body = new StringEntity("city=hamburg&label=" + URLEncoder.encode("Send via Signpost!", "UTF-8"));
body.setContentType("application/x-www-form-urlencoded");
request.setEntity(body);
consumer.sign(request);
System.out.println("Sending update request to Fire Eagle...");
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
System.out.println("Response: " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase());
}
use of oauth.signpost.commonshttp.CommonsHttpOAuthConsumer in project Brion-Learns-OAuth by brione.
the class App method onCreate.
@Override
public void onCreate() {
super.onCreate();
// Only works with my code unless you create your own MyKeysProvider class
this.setKeysProvider(new MyKeysProvider());
mConsumer = new CommonsHttpOAuthConsumer(getKeysProvider().getKey1(), getKeysProvider().getKey2());
mProvider = new CommonsHttpOAuthProvider(App.TWITTER_REQUEST_TOKEN_URL, App.TWITTER_ACCESS_TOKEN_URL, App.TWITTER_AUTHORIZE_URL);
Assert.assertNotNull(mConsumer);
Assert.assertNotNull(mProvider);
mProvider.setOAuth10a(true);
}
use of oauth.signpost.commonshttp.CommonsHttpOAuthConsumer in project mobile-android by photo.
the class Preferences method getOAuthConsumer.
public static OAuthConsumer getOAuthConsumer(Context context) {
if (!isLoggedIn(context)) {
return null;
}
SharedPreferences prefs = getSharedPreferences("oauth");
OAuthConsumer consumer = new CommonsHttpOAuthConsumer(prefs.getString(context.getString(R.string.setting_oauth_consumer_key), null), prefs.getString(context.getString(R.string.setting_oauth_consumer_secret), null));
consumer.setTokenWithSecret(prefs.getString(context.getString(R.string.setting_oauth_token), null), prefs.getString(context.getString(R.string.setting_oauth_token_secret), null));
return consumer;
}
Aggregations