oauth.signpost.http.HttpParameters Java Examples

The following examples show how to use oauth.signpost.http.HttpParameters. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LtiOauthSigner.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public HttpRequest sign(HttpRequest request, String key, String secret) throws LtiSigningException {
    CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
    try {
        String body = getRequestBody(request);
        String bodyHash = new String(Base64.encodeBase64(md.digest(body.getBytes())));

        HttpParameters params = new HttpParameters();
        params.put("oauth_body_hash", URLEncoder.encode(bodyHash, "UTF-8"));
        signer.setAdditionalParameters(params);

        signer.sign(request);
    } catch (OAuthMessageSignerException|OAuthExpectationFailedException|OAuthCommunicationException|IOException e) {
        throw new LtiSigningException("Exception encountered while singing Lti request...", e);
    }
    return request;
}
 
Example #2
Source File: IMSPOXRequest.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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));
	}
	//*LAMS* the following line was added by LAMS and also messageIdentifier was added to the line after it
	String messageIdentifier = UUID.randomUUID().toString();
	String xml = String.format(replaceResultMessage, messageIdentifier, 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;
}
 
Example #3
Source File: RsaSha1MessageSigner.java    From jira-steps-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public String sign(HttpRequest request, HttpParameters requestParams)
    throws OAuthMessageSignerException {

  final OAuthRsaSigner signer = new OAuthRsaSigner();
  final byte[] privateBytes = Base64.decodeBase64(getConsumerSecret());
  final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateBytes);

  try {
    signer.privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
    final String signatureBaseString = new SignatureBaseString(request, requestParams).generate();
    return signer.computeSignature(signatureBaseString);
  } catch (GeneralSecurityException e) {
    throw new OAuthMessageSignerException(e);
  }
}
 
Example #4
Source File: LtiOauthSigner.java    From basiclti-util-java with Apache License 2.0 6 votes vote down vote up
@Override
public HttpRequest sign(HttpRequest request, String key, String secret) throws LtiSigningException {
    CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
    try {
        String body = getRequestBody(request);
        String bodyHash = new String(Base64.encodeBase64(md.digest(body.getBytes())));

        HttpParameters params = new HttpParameters();
        params.put("oauth_body_hash", URLEncoder.encode(bodyHash, "UTF-8"));
        signer.setAdditionalParameters(params);

        signer.sign(request);
    } catch (OAuthMessageSignerException|OAuthExpectationFailedException|OAuthCommunicationException|IOException e) {
        throw new LtiSigningException("Exception encountered while singing Lti request...", e);
    }
    return request;
}
 
Example #5
Source File: OAuth1Utils.java    From shimmer with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the request_token response from an initial oauth1 initiate request.
 *
 * @param requestTokenResponse - Response from external data provider
 * @return - Map with token and token secret.
 * @throws ShimException
 */
public static Map<String, String> parseRequestTokenResponse(
    HttpResponse requestTokenResponse) throws ShimException {

    String tokenString;
    try {
        tokenString = IOUtils.toString(requestTokenResponse.getEntity().getContent(), "UTF-8");
    } catch (IOException e) {
        throw new ShimException("Error reading request token", e);
    }
    HttpParameters responseParams = OAuth.decodeForm(tokenString);
    Map<String, String> token = new HashMap<>();
    token.put(
        OAuth.OAUTH_TOKEN,
        responseParams.getFirst(OAuth.OAUTH_TOKEN));
    token.put(
        OAuth.OAUTH_TOKEN_SECRET,
        responseParams.getFirst(OAuth.OAUTH_TOKEN_SECRET));
    return token;
}
 
Example #6
Source File: IMSPOXRequest.java    From basiclti-util-java with Apache License 2.0 5 votes vote down vote up
public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid,
	String score, String resultData, Boolean isUrl, String messageId) throws IOException, OAuthException, GeneralSecurityException
{
	String dataXml = "";
	if (resultData != null) {
		String format = isUrl ? resultDataUrl : resultDataText;
		dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData));
	}

	String messageIdentifier = StringUtils.isBlank(messageId) ? String.valueOf(new Date().getTime()) : messageId;
	String xml = String.format(ReplaceResultMessageTemplate,
		StringEscapeUtils.escapeXml(messageIdentifier),
		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;
}
 
Example #7
Source File: WithingsAccount.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
public void setOuathToken(String token, String tokenSecret) {
    this.token = token;
    this.tokenSecret = tokenSecret;
    consumer.setTokenWithSecret(token, tokenSecret);
    consumer.setAdditionalParameters(new HttpParameters());
}