@Test
public void testOAuthClientFlow() throws Exception {
final String uri = getBaseUri().toString();
final OAuth1AuthorizationFlow authFlow = OAuth1ClientSupport
.builder(new ConsumerCredentials("dpf43f3p2l4k3l03", "kd94hf93k423kf44"))
.timestamp("1191242090")
.nonce("hsu94j3884jdopsl")
.signatureMethod("PLAINTEXT")
.authorizationFlow(
uri + "request_token",
uri + "access_token",
uri + "authorize")
.enableLogging()
.build();
// Check we have correct authorization URI.
final String authorizationUri = authFlow.start();
assertThat(authorizationUri, containsString("authorize?oauth_token=hh5s93j4hdidpola"));
// For the purpose of the test I need parameters (and there is no way how to do it now).
final Field paramField = authFlow.getClass().getDeclaredField("parameters");
paramField.setAccessible(true);
final OAuth1Parameters params = (OAuth1Parameters) paramField.get(authFlow);
// Update parameters.
params.timestamp("1191242092").nonce("dji430splmx33448");
final AccessToken accessToken = authFlow.finish();
assertThat(accessToken, equalTo(new AccessToken("nnch734d00sl2jdk", "pfkkdhi9sl3r4s00")));
// Update parameters before creating a feature (i.e. changing signature method).
params.nonce("kllo9940pd9333jh").signatureMethod("HMAC-SHA1").timestamp("1191242096");
// Check Authorized Client.
final Client flowClient = authFlow.getAuthorizedClient().register(LoggingFilter.class);
String responseEntity = flowClient.target(uri).path("/photos")
.queryParam("file", "vacation.jpg")
.queryParam("size", "original")
.request()
.get(String.class);
assertThat("Flow Authorized Client", responseEntity, equalTo("PHOTO"));
// Check Feature.
final Client featureClient = ClientBuilder.newClient()
.register(authFlow.getOAuth1Feature()).register(LoggingFilter.class);
responseEntity = featureClient.target(uri).path("/photos")
.queryParam("file", "vacation.jpg")
.queryParam("size", "original")
.request()