use of oauth.signpost.OAuthConsumer in project signpost-examples by mttkay.
the class NetflixMain method main.
public static void main(String[] args) throws Exception {
OAuthConsumer consumer = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
OAuthProvider provider = new DefaultOAuthProvider(NETFLIX_REQUEST_TOKEN_URL, NETFLIX_ACCESS_TOKEN_URL, NETFLIX_AUTHORIZE_URL);
System.out.println("Fetching request token from Netflix...");
// we do not support callbacks, thus pass OOB
String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
authUrl = OAuth.addQueryParameters(authUrl, OAuth.OAUTH_CONSUMER_KEY, CONSUMER_KEY, "application_name", APPLICATION_NAME);
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://api.netflix.com/catalog/titles");
HttpURLConnection request = (HttpURLConnection) url.openConnection();
consumer.sign(request);
System.out.println("Sending request...");
request.connect();
System.out.println("Response: " + request.getResponseCode() + " " + request.getResponseMessage());
}
use of oauth.signpost.OAuthConsumer 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);
}
}
use of oauth.signpost.OAuthConsumer 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 oauth.signpost.OAuthConsumer 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