Search in sources :

Example 1 with HttpParameters

use of oauth.signpost.http.HttpParameters in project ArTEMiS by ls1intum.

the class PatchedIMSPOXRequest method buildReplaceResult.

public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid, String score, String resultData, Boolean isUrl) throws IOException, OAuthException, GeneralSecurityException {
    String dataXml = "";
    if (resultData != null) {
        String format = isUrl ? resultDataUrl : resultDataText;
        dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData));
    }
    String xml = String.format(patchedReplaceResultMessage, StringEscapeUtils.escapeXml(sourcedid), StringEscapeUtils.escapeXml(score), dataXml);
    HttpParameters parameters = new HttpParameters();
    String hash = getBodyHash(xml);
    parameters.put("oauth_body_hash", URLEncoder.encode(hash, "UTF-8"));
    CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
    HttpPost request = new HttpPost(url);
    request.setHeader("Content-Type", "application/xml");
    request.setEntity(new StringEntity(xml, "UTF-8"));
    signer.setAdditionalParameters(parameters);
    signer.sign(request);
    return request;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CommonsHttpOAuthConsumer(oauth.signpost.commonshttp.CommonsHttpOAuthConsumer) HttpParameters(oauth.signpost.http.HttpParameters)

Example 2 with HttpParameters

use of oauth.signpost.http.HttpParameters in project serverless by bluenimble.

the class OAuthHttpRequestVisitor method visit.

@Override
public void visit(HttpRequest request, HttpURLConnection connection) throws HttpRequestWriteException {
    HttpEndpoint endpoint = ((AbstractHttpRequest) request).getEndpoint();
    OAuthConsumer consumer = new DefaultOAuthConsumer(key, secret);
    HttpParameters encodedParams = new HttpParameters();
    List<HttpParameter> params = request.getParameters();
    if (params != null && !params.isEmpty()) {
        for (HttpParameter p : params) {
            if (p.getValue() != null) {
                encodedParams.put(p.getName(), OAuth.percentEncode(String.valueOf(p.getValue())));
            }
        }
    }
    encodedParams.put("realm", endpoint.getScheme() + "://" + endpoint.getHost() + endpoint.getPath());
    consumer.setAdditionalParameters(encodedParams);
    try {
        consumer.sign(connection);
    } catch (Exception e) {
        throw new HttpRequestWriteException(e.getMessage(), e);
    }
}
Also used : HttpParameters(oauth.signpost.http.HttpParameters) AbstractHttpRequest(com.bluenimble.platform.http.request.impls.AbstractHttpRequest) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) OAuthConsumer(oauth.signpost.OAuthConsumer) HttpEndpoint(com.bluenimble.platform.http.HttpEndpoint) HttpParameter(com.bluenimble.platform.http.HttpParameter) HttpRequestWriteException(com.bluenimble.platform.http.request.HttpRequestWriteException) HttpRequestWriteException(com.bluenimble.platform.http.request.HttpRequestWriteException)

Example 3 with HttpParameters

use of oauth.signpost.http.HttpParameters in project Parse-SDK-Android by ParsePlatform.

the class Twitter method authorize.

public void authorize(final Context context, final AsyncCallback callback) {
    if (getConsumerKey() == null || getConsumerKey().length() == 0 || getConsumerSecret() == null || getConsumerSecret().length() == 0) {
        throw new IllegalStateException("Twitter must be initialized with a consumer key and secret before authorization.");
    }
    final OkHttpOAuthProvider provider = new OkHttpOAuthProvider(REQUEST_TOKEN_URL, ACCESS_TOKEN_URL, AUTHORIZE_URL);
    final OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(getConsumerKey(), getConsumerSecret());
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final Handler handler = new Handler(Looper.getMainLooper());
    executor.execute(() -> {
        Throwable error = null;
        String requestToken = null;
        try {
            requestToken = provider.retrieveRequestToken(consumer, callbackUrl);
        } catch (Throwable e) {
            error = e;
        }
        final Throwable finalError = error;
        final String finalRequestToken = requestToken;
        handler.post(() -> {
            if (finalError != null) {
                callback.onFailure(finalError);
                return;
            }
            OAuth1FlowDialog dialog = new OAuth1FlowDialog(context, finalRequestToken, callbackUrl, "api.twitter", new FlowResultHandler() {

                @Override
                public void onError(int errorCode, String description, String failingUrl) {
                    callback.onFailure(new OAuth1FlowException(errorCode, description, failingUrl));
                }

                @Override
                public void onComplete(String callbackUrl) {
                    CookieManager.getInstance().flush();
                    final Uri uri = Uri.parse(callbackUrl);
                    final String verifier = uri.getQueryParameter(VERIFIER_PARAM);
                    if (verifier == null) {
                        callback.onCancel();
                        return;
                    }
                    executor.execute(() -> {
                        Throwable error = null;
                        HttpParameters parameters = null;
                        try {
                            provider.retrieveAccessToken(consumer, verifier);
                            parameters = provider.getResponseParameters();
                        } catch (Throwable e) {
                            error = e;
                        }
                        final Throwable finalError = error;
                        final HttpParameters finalParameters = parameters;
                        handler.post(() -> {
                            if (finalError != null) {
                                callback.onFailure(finalError);
                                return;
                            }
                            try {
                                setAuthToken(consumer.getToken());
                                setAuthTokenSecret(consumer.getTokenSecret());
                                setScreenName(finalParameters.getFirst(SCREEN_NAME_PARAM));
                                setUserId(finalParameters.getFirst(USER_ID_PARAM));
                            } catch (Throwable e) {
                                callback.onFailure(e);
                                return;
                            }
                            callback.onSuccess(Twitter.this);
                        });
                    });
                }

                @Override
                public void onCancel() {
                    callback.onCancel();
                }
            });
            dialog.show();
        });
    });
}
Also used : FlowResultHandler(com.parse.twitter.OAuth1FlowDialog.FlowResultHandler) HttpParameters(oauth.signpost.http.HttpParameters) OkHttpOAuthProvider(se.akerfeldt.okhttp.signpost.OkHttpOAuthProvider) FlowResultHandler(com.parse.twitter.OAuth1FlowDialog.FlowResultHandler) Handler(android.os.Handler) Uri(android.net.Uri) OkHttpOAuthConsumer(se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer) ExecutorService(java.util.concurrent.ExecutorService)

Example 4 with HttpParameters

use of oauth.signpost.http.HttpParameters in project OpenRefine by OpenRefine.

the class AuthorizationHeaderSigningStrategy method writeSignature.

public String writeSignature(String signature, HttpRequest request, HttpParameters requestParameters) {
    StringBuilder sb = new StringBuilder();
    sb.append("OAuth ");
    if (realm != null) {
        sb.append("realm=\"" + realm + "\", ");
    }
    // add all (x_)oauth parameters
    HttpParameters oauthParams = requestParameters.getOAuthParameters();
    oauthParams.put(OAuth.OAUTH_SIGNATURE, signature, true);
    Iterator<String> iter = oauthParams.keySet().iterator();
    while (iter.hasNext()) {
        String key = iter.next();
        sb.append(oauthParams.getAsHeaderElement(key));
        if (iter.hasNext()) {
            sb.append(", ");
        }
    }
    String header = sb.toString();
    OAuth.debugOut("Auth Header", header);
    request.setHeader(OAuth.HTTP_AUTHORIZATION_HEADER, header);
    return header;
}
Also used : HttpParameters(oauth.signpost.http.HttpParameters)

Example 5 with HttpParameters

use of oauth.signpost.http.HttpParameters in project openhab1-addons by openhab.

the class WithingsAccount method setOuathToken.

public void setOuathToken(String token, String tokenSecret) {
    this.token = token;
    this.tokenSecret = tokenSecret;
    consumer.setTokenWithSecret(token, tokenSecret);
    consumer.setAdditionalParameters(new HttpParameters());
}
Also used : HttpParameters(oauth.signpost.http.HttpParameters)

Aggregations

HttpParameters (oauth.signpost.http.HttpParameters)5 Uri (android.net.Uri)1 Handler (android.os.Handler)1 HttpEndpoint (com.bluenimble.platform.http.HttpEndpoint)1 HttpParameter (com.bluenimble.platform.http.HttpParameter)1 HttpRequestWriteException (com.bluenimble.platform.http.request.HttpRequestWriteException)1 AbstractHttpRequest (com.bluenimble.platform.http.request.impls.AbstractHttpRequest)1 FlowResultHandler (com.parse.twitter.OAuth1FlowDialog.FlowResultHandler)1 ExecutorService (java.util.concurrent.ExecutorService)1 OAuthConsumer (oauth.signpost.OAuthConsumer)1 DefaultOAuthConsumer (oauth.signpost.basic.DefaultOAuthConsumer)1 CommonsHttpOAuthConsumer (oauth.signpost.commonshttp.CommonsHttpOAuthConsumer)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1 OkHttpOAuthConsumer (se.akerfeldt.okhttp.signpost.OkHttpOAuthConsumer)1 OkHttpOAuthProvider (se.akerfeldt.okhttp.signpost.OkHttpOAuthProvider)1