Search in sources :

Example 1 with GoogleOAuthConsumer

use of org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer 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 2 with GoogleOAuthConsumer

use of org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer in project data-transfer-project by google.

the class SmugMugAuth method generateConsumer.

OAuthConsumer generateConsumer(AuthData authData) {
    Preconditions.checkArgument(authData instanceof TokenSecretAuthData, "authData expected to be TokenSecretAuthData not %s", authData.getClass().getCanonicalName());
    TokenSecretAuthData tokenSecretAuthData = (TokenSecretAuthData) authData;
    OAuthConsumer consumer = new GoogleOAuthConsumer(appCredentials.key(), appCredentials.secret());
    consumer.setTokenWithSecret(tokenSecretAuthData.token(), tokenSecretAuthData.secret());
    return consumer;
}
Also used : TokenSecretAuthData(org.dataportabilityproject.shared.auth.TokenSecretAuthData) GoogleOAuthConsumer(org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer) OAuthConsumer(oauth.signpost.OAuthConsumer) GoogleOAuthConsumer(org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer)

Aggregations

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