Search in sources :

Example 1 with HttpClient4

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);
    }
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) HttpClient4(net.oauth.client.httpclient4.HttpClient4) OAuthMessage(net.oauth.OAuthMessage) OAuthClient(net.oauth.client.OAuthClient) OAuth(net.oauth.OAuth)

Example 2 with HttpClient4

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);
    }
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) HttpClient4(net.oauth.client.httpclient4.HttpClient4) OAuthMessage(net.oauth.OAuthMessage) OAuthClient(net.oauth.client.OAuthClient)

Example 3 with HttpClient4

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);
    }
}
Also used : OAuthAccessor(net.oauth.OAuthAccessor) HttpClient4(net.oauth.client.httpclient4.HttpClient4) OAuthMessage(net.oauth.OAuthMessage) OAuthClient(net.oauth.client.OAuthClient)

Aggregations

OAuthAccessor (net.oauth.OAuthAccessor)3 OAuthMessage (net.oauth.OAuthMessage)3 OAuthClient (net.oauth.client.OAuthClient)3 HttpClient4 (net.oauth.client.httpclient4.HttpClient4)3 OAuth (net.oauth.OAuth)1