Search in sources :

Example 36 with OAuthRequest

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

the class OAuth20Service method createRefreshTokenRequest.

protected OAuthRequest createRefreshTokenRequest(String refreshToken) {
    if (refreshToken == null || refreshToken.isEmpty()) {
        throw new IllegalArgumentException("The refreshToken cannot be null or empty");
    }
    final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint());
    final OAuthConfig config = getConfig();
    request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken);
    request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN);
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 37 with OAuthRequest

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

the class OkHttpHttpClientTest method shouldReadResponseStream.

@Test
public void shouldReadResponseStream() throws Exception {
    final String expectedResponseBody = "response body";
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody(expectedResponseBody));
    server.start();
    final HttpUrl baseUrl = server.url("/testUrl");
    final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString());
    final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
    assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream()));
    final RecordedRequest recordedRequest = server.takeRequest();
    assertEquals("GET", recordedRequest.getMethod());
    server.shutdown();
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response) MockResponse(okhttp3.mockwebserver.MockResponse) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) MockWebServer(okhttp3.mockwebserver.MockWebServer) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 38 with OAuthRequest

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

the class OkHttpHttpClientTest method shouldSendPostRequest.

@Test
public void shouldSendPostRequest() throws Exception {
    final String expectedResponseBody = "response body";
    final String expectedRequestBody = "request body";
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody(expectedResponseBody));
    server.enqueue(new MockResponse().setBody(expectedResponseBody));
    server.start();
    final HttpUrl baseUrl = server.url("/testUrl");
    // request with body
    OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString());
    request.setPayload(expectedRequestBody);
    Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
    assertEquals(expectedResponseBody, response.getBody());
    RecordedRequest recordedRequest = server.takeRequest();
    assertEquals("POST", recordedRequest.getMethod());
    assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8());
    // request with empty body
    request = new OAuthRequest(Verb.POST, baseUrl.toString());
    response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
    assertEquals(expectedResponseBody, response.getBody());
    recordedRequest = server.takeRequest();
    assertEquals("POST", recordedRequest.getMethod());
    assertEquals("", recordedRequest.getBody().readUtf8());
    server.shutdown();
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response) MockResponse(okhttp3.mockwebserver.MockResponse) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) MockWebServer(okhttp3.mockwebserver.MockWebServer) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 39 with OAuthRequest

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

the class OkHttpHttpClientTest method shouldSendGetRequest.

@Test
public void shouldSendGetRequest() throws Exception {
    final String expectedResponseBody = "response body";
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody(expectedResponseBody));
    server.start();
    final HttpUrl baseUrl = server.url("/testUrl");
    final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString());
    final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
    assertEquals(expectedResponseBody, response.getBody());
    final RecordedRequest recordedRequest = server.takeRequest();
    assertEquals("GET", recordedRequest.getMethod());
    server.shutdown();
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response) MockResponse(okhttp3.mockwebserver.MockResponse) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) MockWebServer(okhttp3.mockwebserver.MockWebServer) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 40 with OAuthRequest

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

the class ObjectMother method createSampleOAuthRequestPort80v2.

public static OAuthRequest createSampleOAuthRequestPort80v2() {
    final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test");
    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)

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