oauth.signpost.basic.DefaultOAuthConsumer Java Examples

The following examples show how to use oauth.signpost.basic.DefaultOAuthConsumer. 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: OsmConnection.java    From osmapi with GNU Lesser General Public License v3.0 6 votes vote down vote up
private OAuthConsumer createOAuthConsumer() throws OAuthExpectationFailedException
{
	synchronized(oauthLock)
	{
		if(oauth == null)
		{
			throw new OAuthExpectationFailedException(
					"This class has been initialized without a OAuthConsumer. Only API calls " +
					"that do not require authentication can be made.");
		}

		// "clone" the original consumer every time because the consumer is documented to be not
		// thread safe and maybe multiple threads are making calls to this class
		OAuthConsumer consumer = new DefaultOAuthConsumer(
				oauth.getConsumerKey(), oauth.getConsumerSecret());
		consumer.setTokenWithSecret(oauth.getToken(), oauth.getTokenSecret());
		return consumer;
	}
}
 
Example #2
Source File: BurpExtender.java    From burp-oauth with MIT License 6 votes vote down vote up
@Override
public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequestResponse messageInfo)
{
	if (messageIsRequest && shouldSign(messageInfo))
	{
		HttpRequest req = new BurpHttpRequestWrapper(messageInfo);
		OAuthConsumer consumer = new DefaultOAuthConsumer(
				OAuthConfig.getConsumerKey(),
				OAuthConfig.getConsumerSecret());
		consumer.setTokenWithSecret(OAuthConfig.getToken(),
				OAuthConfig.getTokenSecret());
		try {
			consumer.sign(req);
		} catch (OAuthException oae) {
			oae.printStackTrace();
		}
	}
}
 
Example #3
Source File: Authenticator.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
public static OAuthConsumer createOAuthConsumer(OAuthConsumer oauth) throws OAuthExpectationFailedException {
    if (oauth == null) {
        throw new OAuthExpectationFailedException(
                "This class has been initialized without a OAuthConsumer. Only API calls " +
                        "that do not require authentication can be made.");
    }

    // "clone" the original consumer every time because the consumer is documented to be not
    // thread safe and maybe multiple threads are making calls to this class
    OAuthConsumer consumer = new DefaultOAuthConsumer(
            oauth.getConsumerKey(), oauth.getConsumerSecret());
    consumer.setTokenWithSecret(oauth.getToken(), oauth.getTokenSecret());
    return consumer;
}
 
Example #4
Source File: ConnectionTestFactory.java    From osmapi with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static OAuthConsumer createConsumerThatProhibitsEverything()
{
	OAuthConsumer result = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
	result.setTokenWithSecret(
			"RCamNf4TT7uNeFjmigvOUWhajp5ERFZmcN1qvi7a",
			"72dzmAvuNBEOVKkif3JSYdzMlAq2dw5OnIG75dtX");
	return result;
}
 
Example #5
Source File: ConnectionTestFactory.java    From osmapi with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static OAuthConsumer createConsumerThatAllowsEverything()
{
	OAuthConsumer result = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
	result.setTokenWithSecret(
			"2C4LiOQBOn96kXHyal7uzMJiqpCsiyDBvb8pomyX",
			"1bFMIQpgmu5yjywt3kknopQpcRmwJ6snDDGF7kdr");
	return result;
}
 
Example #6
Source File: OAuth1Utils.java    From shimmer with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an oauth consumer used for signing request URLs.
 *
 * @return The OAuthConsumer.
 */
public static OAuthConsumer createOAuthConsumer(String clientId, String clientSecret) {
    OAuthConsumer consumer =
        new DefaultOAuthConsumer(clientId, clientSecret);
    consumer.setSigningStrategy(new QueryStringSigningStrategy());
    return consumer;
}
 
Example #7
Source File: WSUrlFetch.java    From restcommander with Apache License 2.0 5 votes vote down vote up
private HttpURLConnection prepare(URL url, String method) {
    if (this.username != null && this.password != null && this.scheme != null) {
        String authString = null;
        switch (this.scheme) {
        case BASIC: authString = basicAuthHeader(); break;
        default: throw new RuntimeException("Scheme " + this.scheme + " not supported by the UrlFetch WS backend.");
        }
        this.headers.put("Authorization", authString);
    }
    try {
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod(method);
        connection.setDoInput(true);
        connection.setInstanceFollowRedirects(this.followRedirects);
        connection.setReadTimeout(this.timeout * 1000);
        for (String key: this.headers.keySet()) {
            connection.setRequestProperty(key, headers.get(key));
        }
        checkFileBody(connection);
        if (this.oauthToken != null && this.oauthSecret != null) {
            OAuthConsumer consumer = new DefaultOAuthConsumer(oauthInfo.consumerKey, oauthInfo.consumerSecret);
            consumer.setTokenWithSecret(oauthToken, oauthSecret);
            consumer.sign(connection);
        }
        return connection;
    } catch(Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #8
Source File: OAuth.java    From restcommander with Apache License 2.0 5 votes vote down vote up
/**
 * Request the request token and secret.
 * @param callbackURL the URL where the provider should redirect to
 * @return a Response object holding either the result in case of a success or the error
 */
public Response retrieveRequestToken(String callbackURL) {
    OAuthConsumer consumer = new DefaultOAuthConsumer(info.consumerKey, info.consumerSecret);
    try {
        provider.retrieveRequestToken(consumer, callbackURL);
    } catch (OAuthException e) {
        return Response.error(new Error(e));
    }
    return Response.success(consumer.getToken(), consumer.getTokenSecret());
}
 
Example #9
Source File: OAuth.java    From restcommander with Apache License 2.0 5 votes vote down vote up
/**
 * Exchange a request token for an access token.
 * @param token the token obtained from a previous call
 * @param secret your application secret
 * @return a Response object holding either the result in case of a success or the error
 */
public Response retrieveAccessToken(String token, String secret) {
     OAuthConsumer consumer = new DefaultOAuthConsumer(info.consumerKey, info.consumerSecret);
    consumer.setTokenWithSecret(token, secret);
    String verifier = Params.current().get("oauth_verifier");
    try {
        provider.retrieveAccessToken(consumer, verifier);
    } catch (OAuthException e) {
        return Response.error(new Error(e));
    }
    return Response.success(consumer.getToken(), consumer.getTokenSecret());
}
 
Example #10
Source File: OAuthTest.java    From burp-oauth with MIT License 5 votes vote down vote up
@Test
public void testSignature() throws Exception {
	HttpRequest hr = reqWrapForTestInput(1);
	OAuthConsumer consumer = new DefaultOAuthConsumer("1234", "5678");
	consumer.setTokenWithSecret("9ABC", "DEF0");
	consumer.sign(hr);
}
 
Example #11
Source File: OAuth.java    From AndroidApp with Mozilla Public License 2.0 4 votes vote down vote up
public static OAuthConsumer createConsumer() {
    return new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
}
 
Example #12
Source File: ConnectionTestFactory.java    From osmapi with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static OAuthConsumer createUnknownUser()
{
	return new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
}
 
Example #13
Source File: WithingsAccount.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
public OAuthConsumer createConsumer() {
    consumer = new DefaultOAuthConsumer(consumerKey, consumerSecret);
    consumer.setSigningStrategy(new AuthorizationHeaderSigningStrategy());
    consumer.setMessageSigner(new HmacSha1MessageSigner());
    return consumer;
}