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());
}
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;
}
Aggregations