Search in sources :

Example 1 with OAuthNotAuthorizedException

use of oauth.signpost.exception.OAuthNotAuthorizedException in project twitterdroid by fbrunel.

the class ConfigActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    try {
        String authURL = provider.retrieveRequestToken(consumer, CALLBACK_URL);
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authURL)));
    } catch (OAuthMessageSignerException e) {
        e.printStackTrace();
    } catch (OAuthNotAuthorizedException e) {
        e.printStackTrace();
    } catch (OAuthExpectationFailedException e) {
        e.printStackTrace();
    } catch (OAuthCommunicationException e) {
        e.printStackTrace();
    }
    finish();
}
Also used : OAuthNotAuthorizedException(oauth.signpost.exception.OAuthNotAuthorizedException) OAuthMessageSignerException(oauth.signpost.exception.OAuthMessageSignerException) OAuthExpectationFailedException(oauth.signpost.exception.OAuthExpectationFailedException) Intent(android.content.Intent) OAuthCommunicationException(oauth.signpost.exception.OAuthCommunicationException)

Example 2 with OAuthNotAuthorizedException

use of oauth.signpost.exception.OAuthNotAuthorizedException 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)

Aggregations

OAuthCommunicationException (oauth.signpost.exception.OAuthCommunicationException)2 OAuthExpectationFailedException (oauth.signpost.exception.OAuthExpectationFailedException)2 OAuthMessageSignerException (oauth.signpost.exception.OAuthMessageSignerException)2 OAuthNotAuthorizedException (oauth.signpost.exception.OAuthNotAuthorizedException)2 Intent (android.content.Intent)1 IOException (java.io.IOException)1 OAuthConsumer (oauth.signpost.OAuthConsumer)1 OAuthProvider (oauth.signpost.OAuthProvider)1 DefaultOAuthProvider (oauth.signpost.basic.DefaultOAuthProvider)1 GoogleOAuthConsumer (org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer)1