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