Search in sources :

Example 31 with OAuthRequest

use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.

the class ObjectMother method createSampleOAuthRequestPort80.

public static OAuthRequest createSampleOAuthRequestPort80() {
    final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80");
    request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456");
    request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&");
    request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback");
    request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature");
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest)

Example 32 with OAuthRequest

use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.

the class OAuth10aService method getRequestToken.

public final OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException {
    final OAuthConfig config = getConfig();
    config.log("obtaining request token from " + api.getRequestTokenEndpoint());
    final OAuthRequest request = prepareRequestTokenRequest();
    config.log("sending request...");
    final Response response = execute(request);
    final String body = response.getBody();
    config.log("response status code: " + response.getCode());
    config.log("response body: " + body);
    return api.getRequestTokenExtractor().extract(response);
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 33 with OAuthRequest

use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.

the class OAuth10aService method getAccessToken.

public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException {
    getConfig().log("obtaining access token from " + api.getAccessTokenEndpoint());
    final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier);
    final Response response = execute(request);
    return api.getAccessTokenExtractor().extract(response);
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response)

Example 34 with OAuthRequest

use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.

the class OAuth20Service method createAccessTokenRequest.

protected OAuthRequest createAccessTokenRequest(String code) {
    final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    final OAuthConfig config = getConfig();
    request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    request.addParameter(OAuthConstants.CODE, code);
    request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
    final String scope = config.getScope();
    if (scope != null) {
        request.addParameter(OAuthConstants.SCOPE, scope);
    }
    request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE);
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 35 with OAuthRequest

use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.

the class OAuth20Service method createAccessTokenPasswordGrantRequest.

protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password) {
    final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    final OAuthConfig config = getConfig();
    request.addParameter(OAuthConstants.USERNAME, username);
    request.addParameter(OAuthConstants.PASSWORD, password);
    final String scope = config.getScope();
    if (scope != null) {
        request.addParameter(OAuthConstants.SCOPE, scope);
    }
    request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD);
    final String apiKey = config.getApiKey();
    final String apiSecret = config.getApiSecret();
    if (apiKey != null && apiSecret != null) {
        request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + Base64Encoder.getInstance().encode(String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8"))));
    }
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Aggregations

OAuthRequest (com.github.scribejava.core.model.OAuthRequest)71 Response (com.github.scribejava.core.model.Response)56 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)49 Scanner (java.util.Scanner)49 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)31 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)30 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)19 OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)19 OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)18 Random (java.util.Random)11 OAuthConfig (com.github.scribejava.core.model.OAuthConfig)9 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 NingHttpClientConfig (com.github.scribejava.httpclient.ning.NingHttpClientConfig)3 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)3 HttpUrl (okhttp3.HttpUrl)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 MockWebServer (okhttp3.mockwebserver.MockWebServer)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 SalesforceToken (com.github.scribejava.apis.salesforce.SalesforceToken)2