Search in sources :

Example 6 with OAuthConsumer

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;
}
Also used : OAuthConsumer(oauth.signpost.OAuthConsumer)

Example 7 with OAuthConsumer

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);
    }
}
Also used : HttpParameters(oauth.signpost.http.HttpParameters) AbstractHttpRequest(com.bluenimble.platform.http.request.impls.AbstractHttpRequest) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) OAuthConsumer(oauth.signpost.OAuthConsumer) HttpEndpoint(com.bluenimble.platform.http.HttpEndpoint) HttpParameter(com.bluenimble.platform.http.HttpParameter) HttpRequestWriteException(com.bluenimble.platform.http.request.HttpRequestWriteException) HttpRequestWriteException(com.bluenimble.platform.http.request.HttpRequestWriteException)

Example 8 with OAuthConsumer

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;
}
Also used : CommonsHttpOAuthConsumer(oauth.signpost.commonshttp.CommonsHttpOAuthConsumer) SharedPreferences(android.content.SharedPreferences) CommonsHttpOAuthConsumer(oauth.signpost.commonshttp.CommonsHttpOAuthConsumer) OAuthConsumer(oauth.signpost.OAuthConsumer)

Example 9 with OAuthConsumer

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());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CommonsHttpOAuthConsumer(oauth.signpost.commonshttp.CommonsHttpOAuthConsumer) CommonsHttpOAuthProvider(oauth.signpost.commonshttp.CommonsHttpOAuthProvider) InputStreamReader(java.io.InputStreamReader) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BufferedReader(java.io.BufferedReader) HttpResponse(org.apache.http.HttpResponse) CommonsHttpOAuthProvider(oauth.signpost.commonshttp.CommonsHttpOAuthProvider) OAuthProvider(oauth.signpost.OAuthProvider) OAuthConsumer(oauth.signpost.OAuthConsumer) CommonsHttpOAuthConsumer(oauth.signpost.commonshttp.CommonsHttpOAuthConsumer) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 10 with OAuthConsumer

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());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) DefaultOAuthProvider(oauth.signpost.basic.DefaultOAuthProvider) BufferedReader(java.io.BufferedReader) DefaultOAuthProvider(oauth.signpost.basic.DefaultOAuthProvider) OAuthProvider(oauth.signpost.OAuthProvider) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) OAuthConsumer(oauth.signpost.OAuthConsumer) URL(java.net.URL)

Aggregations

OAuthConsumer (oauth.signpost.OAuthConsumer)14 OAuthProvider (oauth.signpost.OAuthProvider)6 DefaultOAuthConsumer (oauth.signpost.basic.DefaultOAuthConsumer)5 DefaultOAuthProvider (oauth.signpost.basic.DefaultOAuthProvider)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 CommonsHttpOAuthConsumer (oauth.signpost.commonshttp.CommonsHttpOAuthConsumer)3 IOException (java.io.IOException)2 OAuthException (oauth.signpost.exception.OAuthException)2 GoogleOAuthConsumer (org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer)2 SharedPreferences (android.content.SharedPreferences)1 HttpEndpoint (com.bluenimble.platform.http.HttpEndpoint)1 HttpParameter (com.bluenimble.platform.http.HttpParameter)1 HttpRequestWriteException (com.bluenimble.platform.http.request.HttpRequestWriteException)1 AbstractHttpRequest (com.bluenimble.platform.http.request.impls.AbstractHttpRequest)1 Credentials (com.google.refine.oauth.Credentials)1 Provider (com.google.refine.oauth.Provider)1 URISyntaxException (java.net.URISyntaxException)1