use of oauth.signpost.OAuthConsumer in project StreetComplete by westnordost.
the class OAuthPrefs method loadConsumer.
public OAuthConsumer loadConsumer() {
OAuthConsumer result = oAuthConsumerProvider.get();
String accessToken = prefs.getString(Prefs.OAUTH_ACCESS_TOKEN, null);
String accessTokenSecret = prefs.getString(Prefs.OAUTH_ACCESS_TOKEN_SECRET, null);
result.setTokenWithSecret(accessToken, accessTokenSecret);
return result;
}
use of oauth.signpost.OAuthConsumer in project serverless by bluenimble.
the class OAuthHttpRequestVisitor method visit.
@Override
public void visit(HttpRequest request, HttpURLConnection connection) throws HttpRequestWriteException {
HttpEndpoint endpoint = ((AbstractHttpRequest) request).getEndpoint();
OAuthConsumer consumer = new DefaultOAuthConsumer(key, secret);
HttpParameters encodedParams = new HttpParameters();
List<HttpParameter> params = request.getParameters();
if (params != null && !params.isEmpty()) {
for (HttpParameter p : params) {
if (p.getValue() != null) {
encodedParams.put(p.getName(), OAuth.percentEncode(String.valueOf(p.getValue())));
}
}
}
encodedParams.put("realm", endpoint.getScheme() + "://" + endpoint.getHost() + endpoint.getPath());
consumer.setAdditionalParameters(encodedParams);
try {
consumer.sign(connection);
} catch (Exception e) {
throw new HttpRequestWriteException(e.getMessage(), e);
}
}
use of oauth.signpost.OAuthConsumer 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;
}
use of oauth.signpost.OAuthConsumer 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.OAuthConsumer in project signpost-examples by mttkay.
the class GoogleMain method main.
public static void main(String[] args) throws Exception {
OAuthConsumer consumer = new DefaultOAuthConsumer("matthiaskaeppler.de", "etpfOSfQ4e9xnfgOJETy4D56");
String scope = "http://www.blogger.com/feeds";
OAuthProvider provider = new DefaultOAuthProvider("https://www.google.com/accounts/OAuthGetRequestToken?scope=" + URLEncoder.encode(scope, "utf-8"), "https://www.google.com/accounts/OAuthGetAccessToken", "https://www.google.com/accounts/OAuthAuthorizeToken?hd=default");
System.out.println("Fetching request token...");
String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
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 verificationCode = br.readLine();
System.out.println("Fetching access token...");
provider.retrieveAccessToken(consumer, verificationCode.trim());
System.out.println("Access token: " + consumer.getToken());
System.out.println("Token secret: " + consumer.getTokenSecret());
URL url = new URL("http://www.blogger.com/feeds/default/blogs");
HttpURLConnection request = (HttpURLConnection) url.openConnection();
consumer.sign(request);
System.out.println("Sending request...");
request.connect();
System.out.println("Response: " + request.getResponseCode() + " " + request.getResponseMessage());
}
Aggregations