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