Search in sources :

Example 1 with DefaultOAuthProvider

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

use of oauth.signpost.basic.DefaultOAuthProvider in project mobile-android by photo.

the class Preferences method getOAuthProvider.

public static OAuthProvider getOAuthProvider(Context context) {
    String serverUrl = getServer(context);
    OAuthProvider provider = new DefaultOAuthProvider(serverUrl + "/v1/oauth/token/request", serverUrl + "/v1/oauth/token/access", serverUrl + "/v1/oauth/authorize");
    provider.setOAuth10a(true);
    return provider;
}
Also used : DefaultOAuthProvider(oauth.signpost.basic.DefaultOAuthProvider) OAuthProvider(oauth.signpost.OAuthProvider) DefaultOAuthProvider(oauth.signpost.basic.DefaultOAuthProvider)

Example 3 with DefaultOAuthProvider

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

the class WithingsAuthenticator method startAuthentication.

/**
     * Starts the OAuth authentication flow.
     */
public synchronized void startAuthentication(String accountId) {
    WithingsAccount withingsAccount = getAccount(accountId);
    if (withingsAccount == null) {
        logger.warn("Couldn't find Credentials of Account '{}'. Please check openhab.cfg or withings.cfg.", accountId);
        return;
    }
    OAuthConsumer consumer = withingsAccount.createConsumer();
    provider = new DefaultOAuthProvider(OAUTH_REQUEST_TOKEN_ENDPOINT, OAUTH_ACCESS_TOKEN_ENDPOINT_URL, OAUTH_AUTHORIZE_ENDPOINT_URL);
    try {
        String url = provider.retrieveRequestToken(consumer, this.redirectUrl);
        printSetupInstructions(url);
    } catch (OAuthException ex) {
        logger.error(ex.getMessage(), ex);
        printAuthenticationFailed(ex);
    }
}
Also used : OAuthException(oauth.signpost.exception.OAuthException) DefaultOAuthProvider(oauth.signpost.basic.DefaultOAuthProvider) OAuthConsumer(oauth.signpost.OAuthConsumer)

Example 4 with DefaultOAuthProvider

use of oauth.signpost.basic.DefaultOAuthProvider in project data-transfer-project by google.

the class SmugMugAuth method generateAuthData.

@Override
public AuthData generateAuthData(IOInterface ioInterface) throws IOException {
    // As per details: https://api.smugmug.com/api/v2/doc/tutorial/authorization.html
    // and example:
    // http://stackoverflow.com/questions/15194182/examples-for-oauth1-using-google-api-java-oauth
    // Google library puts signature in header and not in request, see https://oauth.net/1/
    OAuthConsumer consumer = new GoogleOAuthConsumer(appCredentials.key(), appCredentials.secret());
    String permissions = (serviceMode == ServiceMode.EXPORT) ? "Read" : "Add";
    OAuthProvider provider = new DefaultOAuthProvider("https://secure.smugmug.com/services/oauth/1.0a/getRequestToken", "https://secure.smugmug.com/services/oauth/1.0a/getAccessToken", "https://secure.smugmug.com/services/oauth/1.0a/authorize?Access=Full&Permissions=" + permissions);
    String authUrl;
    try {
        authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
    } catch (OAuthMessageSignerException | OAuthNotAuthorizedException | OAuthExpectationFailedException | OAuthCommunicationException e) {
        throw new IOException("Couldn't generate authUrl", e);
    }
    String code = ioInterface.ask("Please visit: " + authUrl + " and enter code:");
    try {
        provider.retrieveAccessToken(consumer, code.trim());
    } catch (OAuthMessageSignerException | OAuthNotAuthorizedException | OAuthExpectationFailedException | OAuthCommunicationException e) {
        throw new IOException("Couldn't authorize", e);
    }
    return TokenSecretAuthData.create(consumer.getToken(), consumer.getTokenSecret());
}
Also used : OAuthNotAuthorizedException(oauth.signpost.exception.OAuthNotAuthorizedException) GoogleOAuthConsumer(org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer) OAuthMessageSignerException(oauth.signpost.exception.OAuthMessageSignerException) OAuthExpectationFailedException(oauth.signpost.exception.OAuthExpectationFailedException) DefaultOAuthProvider(oauth.signpost.basic.DefaultOAuthProvider) OAuthProvider(oauth.signpost.OAuthProvider) DefaultOAuthProvider(oauth.signpost.basic.DefaultOAuthProvider) OAuthConsumer(oauth.signpost.OAuthConsumer) GoogleOAuthConsumer(org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer) IOException(java.io.IOException) OAuthCommunicationException(oauth.signpost.exception.OAuthCommunicationException)

Example 5 with DefaultOAuthProvider

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

DefaultOAuthProvider (oauth.signpost.basic.DefaultOAuthProvider)6 OAuthConsumer (oauth.signpost.OAuthConsumer)5 OAuthProvider (oauth.signpost.OAuthProvider)5 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 DefaultOAuthConsumer (oauth.signpost.basic.DefaultOAuthConsumer)3 IOException (java.io.IOException)1 OAuthCommunicationException (oauth.signpost.exception.OAuthCommunicationException)1 OAuthException (oauth.signpost.exception.OAuthException)1 OAuthExpectationFailedException (oauth.signpost.exception.OAuthExpectationFailedException)1 OAuthMessageSignerException (oauth.signpost.exception.OAuthMessageSignerException)1 OAuthNotAuthorizedException (oauth.signpost.exception.OAuthNotAuthorizedException)1 GoogleOAuthConsumer (org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer)1