Search in sources :

Example 26 with OAuth1RequestToken

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! :)");
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response) Scanner(java.util.Scanner) OAuth1AccessToken(com.github.scribejava.core.model.OAuth1AccessToken) OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder)

Example 27 with OAuth1RequestToken

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! :)");
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response) Scanner(java.util.Scanner) OAuth1AccessToken(com.github.scribejava.core.model.OAuth1AccessToken) OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder)

Example 28 with OAuth1RequestToken

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! :)");
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response) Scanner(java.util.Scanner) OAuth1AccessToken(com.github.scribejava.core.model.OAuth1AccessToken) OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder)

Example 29 with OAuth1RequestToken

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;
}
Also used : OAuth1AccessToken(com.github.scribejava.core.model.OAuth1AccessToken) OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService)

Example 30 with OAuth1RequestToken

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());
            }
        }
    });
}
Also used : OAuth1RequestToken(com.github.scribejava.core.model.OAuth1RequestToken) OAuthException(com.github.scribejava.core.exceptions.OAuthException) AsyncSimpleTask(com.codepath.utils.AsyncSimpleTask) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService) Uri(android.net.Uri) OAuthException(com.github.scribejava.core.exceptions.OAuthException) OAuth20Service(com.github.scribejava.core.oauth.OAuth20Service)

Aggregations

OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)30 OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)24 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)22 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)21 Response (com.github.scribejava.core.model.Response)21 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)20 Scanner (java.util.Scanner)20 OAuthException (com.github.scribejava.core.exceptions.OAuthException)3 IOException (java.io.IOException)3 AsyncSimpleTask (com.codepath.utils.AsyncSimpleTask)2 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 HttpCommunicationException (org.pac4j.core.exception.HttpCommunicationException)2 OAuth10Credentials (org.pac4j.oauth.credentials.OAuth10Credentials)2 OAuthCredentialsException (org.pac4j.oauth.exception.OAuthCredentialsException)2 Uri (android.net.Uri)1 OAuthConfig (com.github.scribejava.core.model.OAuthConfig)1 Token (com.github.scribejava.core.model.Token)1 URI (java.net.URI)1