use of com.github.scribejava.core.model.OAuth1RequestToken in project scribejava by scribejava.
the class FreelancerExample method main.
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
final OAuth10aService service = new ServiceBuilder("your client id").apiSecret("your client secret").scope(SCOPE).build(FreelancerApi.Sandbox.instance());
final Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
final OAuth1RequestToken requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println("(The raw response looks like this: " + requestToken.getRawResponse() + "')");
System.out.println();
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(AUTHORIZE_URL + requestToken.getToken());
System.out.println("And paste the verifier here");
System.out.print(">>");
final String oauthVerifier = in.nextLine();
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier);
System.out.println("Got the Access Token!");
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
request.addHeader("GData-Version", "3.0");
final Response response = service.execute(request);
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
}
use of com.github.scribejava.core.model.OAuth1RequestToken in project scribejava by scribejava.
the class AWeberExample method main.
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY).apiSecret(CONSUMER_SECRET).build(AWeberApi.instance());
final Scanner in = new Scanner(System.in);
System.out.println("=== AWeber's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
final OAuth1RequestToken requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
final String oauthVerifier = in.nextLine();
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier);
System.out.println("Got the Access Token!");
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL);
service.signRequest(accessToken, request);
final Response response = service.execute(request);
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with AWeber and ScribeJava! :)");
}
use of com.github.scribejava.core.model.OAuth1RequestToken in project scribejava by scribejava.
the class TwitterExample method main.
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
final OAuth10aService service = new ServiceBuilder("your client id").apiSecret("your client secret").build(TwitterApi.instance());
final Scanner in = new Scanner(System.in);
System.out.println("=== Twitter's OAuth Workflow ===");
System.out.println();
// Obtain the Request Token
System.out.println("Fetching the Request Token...");
final OAuth1RequestToken requestToken = service.getRequestToken();
System.out.println("Got the Request Token!");
System.out.println();
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
final String oauthVerifier = in.nextLine();
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier);
System.out.println("Got the Access Token!");
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
final Response response = service.execute(request);
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getBody());
System.out.println();
System.out.println("That's it man! Go and build something awesome with ScribeJava! :)");
}
use of com.github.scribejava.core.model.OAuth1RequestToken in project wikidata-query-rdf by wikimedia.
the class OAuthProxyServiceUnitTest method getMockedMWOAuthService.
private OAuth10aService getMockedMWOAuthService() throws IOException, InterruptedException, ExecutionException {
OAuth10aService mwoauthServiceMock = mock(OAuth10aService.class);
OAuth1RequestToken requestToken = new OAuth1RequestToken(OAUTH_TOKEN_STRING, "tokenSecret");
when(mwoauthServiceMock.getRequestToken()).thenReturn(requestToken);
when(mwoauthServiceMock.getAuthorizationUrl(requestToken)).thenReturn(AUTHORIZE_URL);
OAuth1AccessToken accessToken = new OAuth1AccessToken("access_token", "access_token_secret");
when(mwoauthServiceMock.getAccessToken(requestToken, OAUTH_VERIFIER_STR)).thenReturn(accessToken);
return mwoauthServiceMock;
}
use of com.github.scribejava.core.model.OAuth1RequestToken in project android-oauth-handler by codepath.
the class OAuthAsyncHttpClient method fetchAccessToken.
// Get the access token by exchanging the requestToken to the defined URL
// Once receiving the access token, fires the onReceivedAccessToken method on the handler
public void fetchAccessToken(final Token requestToken, final Uri uri) {
new AsyncSimpleTask(new AsyncSimpleTask.AsyncSimpleTaskHandler() {
Exception e = null;
public void doInBackground() {
// Fetch the verifier code from redirect url parameters
Uri authorizedUri = uri;
try {
if (service.getVersion() == "1.0") {
if (authorizedUri.getQuery().contains(OAuthConstants.VERIFIER)) {
String oauth_verifier = authorizedUri.getQueryParameter(OAuthConstants.VERIFIER);
OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken;
OAuth10aService oAuth10aService = (OAuth10aService) service;
accessToken = oAuth10aService.getAccessToken(oAuth1RequestToken, oauth_verifier);
} else {
// verifier was null
throw new OAuthException("No verifier code was returned with uri '" + uri + "' " + "and access token cannot be retrieved");
}
} else if (service.getVersion() == "2.0") {
if (authorizedUri.getQuery().contains(OAuthConstants.CODE)) {
String code = authorizedUri.getQueryParameter(OAuthConstants.CODE);
OAuth20Service oAuth20Service = (OAuth20Service) service;
accessToken = oAuth20Service.getAccessToken(code);
} else {
// verifier was null
throw new OAuthException("No code was returned with uri '" + uri + "' " + "and access token cannot be retrieved");
}
}
} catch (Exception e) {
this.e = e;
}
}
public void onPostExecute() {
if (e != null) {
handler.onFailure(e);
} else {
setAccessToken(accessToken);
handler.onReceivedAccessToken(accessToken, service.getVersion());
}
}
});
}
Aggregations