Search in sources :

Example 1 with DefaultOAuthConsumer

use of oauth.signpost.basic.DefaultOAuthConsumer in project signpost-examples by mttkay.

the class TwitterMain method main.

public static void main(String[] args) throws Exception {
    OAuthConsumer consumer = new DefaultOAuthConsumer("iIlNngv1KdV6XzNYkoLA", "exQ94pBpLXFcyttvLoxU2nrktThrlsj580zjYzmoM", SignatureMethod.HMAC_SHA1);
    OAuthProvider provider = new DefaultOAuthProvider("https://api.twitter.com/oauth/request_token", "https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/authorize");
    System.out.println("Fetching request token from Twitter...");
    // we do not support callbacks, thus pass OOB
    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 PIN code and hit ENTER when you're done:");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String pin = br.readLine();
    System.out.println("Fetching access token from Twitter...");
    provider.retrieveAccessToken(consumer, pin);
    System.out.println("Access token: " + consumer.getToken());
    System.out.println("Token secret: " + consumer.getTokenSecret());
    URL url = new URL("http://twitter.com/statuses/mentions.xml");
    HttpURLConnection request = (HttpURLConnection) url.openConnection();
    consumer.sign(request);
    System.out.println("Sending request to Twitter...");
    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)

Example 2 with DefaultOAuthConsumer

use of oauth.signpost.basic.DefaultOAuthConsumer in project openhab1-addons by openhab.

the class WithingsAccount method createConsumer.

public OAuthConsumer createConsumer() {
    consumer = new DefaultOAuthConsumer(consumerKey, consumerSecret);
    consumer.setSigningStrategy(new AuthorizationHeaderSigningStrategy());
    consumer.setMessageSigner(new HmacSha1MessageSigner());
    return consumer;
}
Also used : HmacSha1MessageSigner(oauth.signpost.signature.HmacSha1MessageSigner) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) AuthorizationHeaderSigningStrategy(oauth.signpost.signature.AuthorizationHeaderSigningStrategy)

Example 3 with DefaultOAuthConsumer

use of oauth.signpost.basic.DefaultOAuthConsumer in project androidquery by androidquery.

the class TwitterHandle method applyToken.

@Override
public void applyToken(AbstractAjaxCallback<?, ?> cb, HttpURLConnection conn) {
    AQUtility.debug("apply token multipart", cb.getUrl());
    OAuthConsumer oac = new DefaultOAuthConsumer(consumer.getConsumerKey(), consumer.getConsumerSecret());
    oac.setTokenWithSecret(consumer.getToken(), consumer.getTokenSecret());
    try {
        oac.sign(conn);
    } catch (Exception e) {
        AQUtility.report(e);
    }
}
Also used : DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) CommonsHttpOAuthConsumer(oauth.signpost.commonshttp.CommonsHttpOAuthConsumer) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) OAuthConsumer(oauth.signpost.OAuthConsumer)

Example 4 with DefaultOAuthConsumer

use of oauth.signpost.basic.DefaultOAuthConsumer 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 5 with DefaultOAuthConsumer

use of oauth.signpost.basic.DefaultOAuthConsumer 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

DefaultOAuthConsumer (oauth.signpost.basic.DefaultOAuthConsumer)6 OAuthConsumer (oauth.signpost.OAuthConsumer)5 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 OAuthProvider (oauth.signpost.OAuthProvider)3 DefaultOAuthProvider (oauth.signpost.basic.DefaultOAuthProvider)3 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 CommonsHttpOAuthConsumer (oauth.signpost.commonshttp.CommonsHttpOAuthConsumer)1 HttpParameters (oauth.signpost.http.HttpParameters)1 AuthorizationHeaderSigningStrategy (oauth.signpost.signature.AuthorizationHeaderSigningStrategy)1 HmacSha1MessageSigner (oauth.signpost.signature.HmacSha1MessageSigner)1