use of net.oauth.client.httpclient4.HttpClient4 in project ngtesting-platform by aaronchen2k.
the class AtlassianOAuthClient method getRequestToken.
public TokenSecretVerifierHolder getRequestToken() {
try {
OAuthAccessor accessor = getAccessor();
OAuthClient oAuthClient = new OAuthClient(new HttpClient4());
List<OAuth.Parameter> callBack;
if (callback == null || "".equals(callback)) {
callBack = Collections.<OAuth.Parameter>emptyList();
} else {
callBack = ImmutableList.of(new OAuth.Parameter(OAuth.OAUTH_CALLBACK, callback));
}
OAuthMessage message = oAuthClient.getRequestTokenResponse(accessor, "POST", callBack);
TokenSecretVerifierHolder tokenSecretVerifier = new TokenSecretVerifierHolder();
tokenSecretVerifier.token = accessor.requestToken;
tokenSecretVerifier.secret = accessor.tokenSecret;
tokenSecretVerifier.verifier = message.getParameter(OAUTH_VERIFIER);
return tokenSecretVerifier;
} catch (Exception e) {
throw new RuntimeException("Failed to obtain request token", e);
}
}
use of net.oauth.client.httpclient4.HttpClient4 in project ngtesting-platform by aaronchen2k.
the class AtlassianOAuthClient method getAuthenticatedRequest.
public String getAuthenticatedRequest(String url, String accessToken, List<OAuth.Parameter> params) {
try {
OAuthAccessor accessor = getAccessor();
OAuthClient client = new OAuthClient(new HttpClient4());
accessor.accessToken = accessToken;
OAuthMessage response = client.invoke(accessor, url, params);
return response.readBodyAsString();
} catch (Exception e) {
throw new RuntimeException("Failed to make an authenticated request.", e);
}
}
use of net.oauth.client.httpclient4.HttpClient4 in project ngtesting-platform by aaronchen2k.
the class AtlassianOAuthClient method swapRequestTokenForAccessToken.
public String swapRequestTokenForAccessToken(String requestToken, String tokenSecret, String oauthVerifier) {
try {
OAuthAccessor accessor = getAccessor();
OAuthClient client = new OAuthClient(new HttpClient4());
accessor.requestToken = requestToken;
accessor.tokenSecret = tokenSecret;
OAuthMessage message = client.getAccessToken(accessor, "POST", ImmutableList.of(new OAuth.Parameter(OAuth.OAUTH_VERIFIER, oauthVerifier)));
return message.getToken();
} catch (Exception e) {
throw new RuntimeException("Failed to swap request token with access token", e);
}
}
Aggregations