当前位置: 首页>>代码示例>>Java>>正文


Java CommonsHttpOAuthConsumer.setTokenWithSecret方法代码示例

本文整理汇总了Java中oauth.signpost.commonshttp.CommonsHttpOAuthConsumer.setTokenWithSecret方法的典型用法代码示例。如果您正苦于以下问题:Java CommonsHttpOAuthConsumer.setTokenWithSecret方法的具体用法?Java CommonsHttpOAuthConsumer.setTokenWithSecret怎么用?Java CommonsHttpOAuthConsumer.setTokenWithSecret使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth.signpost.commonshttp.CommonsHttpOAuthConsumer的用法示例。


在下文中一共展示了CommonsHttpOAuthConsumer.setTokenWithSecret方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getServiceOAuthSigner

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private OAuthSigner getServiceOAuthSigner() throws Exception {
    String password = keyStorePassword(instanceConfig.getRoutesHost(), instanceConfig.getRoutesPort());
    File oauthKeystoreFile = new File("./certs/oauthKeystore");
    RSAKeyPairGenerator generator = new RSAKeyPairGenerator();
    String consumerKey = instanceConfig.getInstanceKey();
    String consumerSecret = generator.getPrivateKey(consumerKey, password, oauthKeystoreFile);

    String token = consumerKey;
    String tokenSecret = consumerSecret;

    return (request) -> {
        CommonsHttpOAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
        oAuthConsumer.setMessageSigner(new RsaSha1MessageSigner());
        oAuthConsumer.setTokenWithSecret(token, tokenSecret);
        return oAuthConsumer.sign(request);
    };
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:18,代码来源:Deployable.java

示例2: TwitterHttpClient

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
/**
 * Creates a twitter consumer by all the secrets
 * 
 * @param consumerKey consumer key
 * @param consumerSecret consumer secret
 * @param token token
 * @param tokenSecret token secret
 */
public TwitterHttpClient(String consumerKey, String consumerSecret, String token, String tokenSecret) {
	
	// Create default http client
	HttpParams httpParams = new BasicHttpParams();
	SchemeRegistry registry = new SchemeRegistry();
	registry.register(new Scheme("http", new PlainSocketFactory(), 80));
	registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
       
	httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, registry), httpParams);
	
	// Set consumer
	consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
	consumer.setTokenWithSecret(token, tokenSecret);
	
}
 
开发者ID:BakingCode,项目名称:ara-twitter,代码行数:24,代码来源:TwitterHttpClient.java

示例3: TwitterToGraphSON

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
public TwitterToGraphSON(final String consumerKey, final String consumerSecret, final String accessToken, final String accessSecret, final String[] seeds)
{
    this.seeds = seeds;

    // Initialize the twitter consumer
    consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
    consumer.setTokenWithSecret(accessToken, accessSecret);
}
 
开发者ID:rjbriody,项目名称:tinkertweet,代码行数:9,代码来源:TwitterToGraphSON.java

示例4: syncClient

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private MiruSyncClient syncClient(MiruSyncSenderConfig config) throws Exception {
    if (config.loopback) {
        return syncReceiver;
    } else {
        String consumerKey = StringUtils.trimToNull(config.oAuthConsumerKey);
        String consumerSecret = StringUtils.trimToNull(config.oAuthConsumerSecret);
        String consumerMethod = StringUtils.trimToNull(config.oAuthConsumerMethod);
        if (consumerKey == null || consumerSecret == null || consumerMethod == null) {
            throw new IllegalStateException("OAuth consumer has not been configured");
        }

        consumerMethod = consumerMethod.toLowerCase();
        if (!consumerMethod.equals("hmac") && !consumerMethod.equals("rsa")) {
            throw new IllegalStateException("OAuth consumer method must be one of HMAC or RSA");
        }

        String scheme = config.senderScheme;
        String host = config.senderHost;
        int port = config.senderPort;

        boolean sslEnable = scheme.equals("https");
        OAuthSigner authSigner = (request) -> {
            CommonsHttpOAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
            oAuthConsumer.setMessageSigner(new HmacSha1MessageSigner());
            oAuthConsumer.setTokenWithSecret(consumerKey, consumerSecret);
            return oAuthConsumer.sign(request);
        };
        HttpClient httpClient = HttpRequestHelperUtils.buildHttpClient(sslEnable,
            config.allowSelfSignedCerts,
            authSigner,
            host,
            port,
            syncConfig.getSyncSenderSocketTimeout());

        return new HttpMiruSyncClient(httpClient,
            mapper,
            "/api/sync/v1/write/activities",
            "/api/sync/v1/register/schema");
    }
}
 
开发者ID:jivesoftware,项目名称:miru,代码行数:41,代码来源:MiruSyncSenders.java

示例5: getSignedRequest

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
/**
 * Signs an HTTP post request for cases where OAuth 1.0 posts are
 * required instead of GET.
 *
 * @param unsignedUrl     - The unsigned URL
 * @param clientId        - The external provider assigned client id
 * @param clientSecret    - The external provider assigned client secret
 * @param token           - The access token
 * @param tokenSecret     - The 'secret' parameter to be used (Note: token secret != client secret)
 * @param oAuthParameters - Any additional parameters
 * @return The request to be signed and sent to external data provider.
 */
public static HttpRequestBase getSignedRequest(HttpMethod method,
                                               String unsignedUrl,
                                               String clientId,
                                               String clientSecret,
                                               String token,
                                               String tokenSecret,
                                               Map<String, String> oAuthParameters) throws ShimException {

    URL requestUrl = buildSignedUrl(unsignedUrl, clientId, clientSecret, token, tokenSecret, oAuthParameters);
    String[] signedParams = requestUrl.toString().split("\\?")[1].split("&");

    HttpRequestBase postRequest = method == HttpMethod.GET ?
        new HttpGet(unsignedUrl) : new HttpPost(unsignedUrl);
    String oauthHeader = "";
    for (String signedParam : signedParams) {
        String[] parts = signedParam.split("=");
        oauthHeader += parts[0] + "=\"" + parts[1] + "\",";
    }
    oauthHeader = "OAuth " + oauthHeader.substring(0, oauthHeader.length() - 1);
    postRequest.setHeader("Authorization", oauthHeader);
    CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(clientId, clientSecret);
    consumer.setSendEmptyTokens(false);
    if (token != null) {
        consumer.setTokenWithSecret(token, tokenSecret);
    }
    try {
        consumer.sign(postRequest);
        return postRequest;
    } catch (
        OAuthMessageSignerException
            | OAuthExpectationFailedException
            | OAuthCommunicationException e) {
        e.printStackTrace();
        throw new ShimException("Could not sign POST request, cannot continue");
    }
}
 
开发者ID:openmhealth,项目名称:shimmer,代码行数:49,代码来源:OAuth1Utils.java

示例6: BrickLinkClient

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
public BrickLinkClient(String consumerKey, String consumerSecret, String tokenValue, String tokenSecret) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
    super();
    consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
    consumer.setTokenWithSecret(tokenValue, tokenSecret);
    SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustAllStrategy()).build();
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, new DefaultHostnameVerifier());
    client = HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
 
开发者ID:kleini,项目名称:bricklink,代码行数:9,代码来源:BrickLinkClient.java

示例7: signRequest

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private void signRequest(HttpUriRequest request)
		throws OAuthMessageSignerException,
		OAuthExpectationFailedException, OAuthCommunicationException {
	CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
			consumerKey, consumerSecret);
	consumer.setTokenWithSecret(accessToken.getToken(),
			accessToken.getTokenSecret());
	consumer.sign(request);
}
 
开发者ID:fsiu,项目名称:dw2020,代码行数:10,代码来源:PxApi.java

示例8: signRequest

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private boolean signRequest(HttpUriRequest request) {
    try {
        CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
                consumerKey, consumerSecret);
        consumer.setTokenWithSecret(accessToken.getToken(),
                accessToken.getTokenSecret());
        consumer.sign(request);
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Error trying to sign the request.", e);
        return false;
    }
}
 
开发者ID:marc-ashman,项目名称:500px,代码行数:14,代码来源:CustomPxApi.java

示例9: createConsumer

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
public OAuthConsumer createConsumer() {
	CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret) {
		private static final long serialVersionUID = 2077439267247908434L;

		@Override
		protected String generateNonce() {
			// thread-safe nonce generation
			// http://code.google.com/p/oauth-signpost/issues/detail?id=41
			return Long.toString(RANDOM.nextLong());
		}
	};
	consumer.setTokenWithSecret(token, tokenSecret);
	return consumer;
}
 
开发者ID:BellaDati,项目名称:belladati-sdk-java,代码行数:15,代码来源:TokenHolder.java

示例10: ShapewaysClient

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
/**
 * Register your app to get a consumer key and secret
 * 
 * @see http://developers.shapeways.com/manage-apps
 * 
 * @param consumerKey
 * @param consumerSecret
 */
public ShapewaysClient(Context context, String consumerKey, String consumerSecret) {
	this.context = context;
	this.consumerKey = consumerKey;
	this.consumerSecret = consumerSecret;

	SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
	// check if OAuth token obtained before
	oauthToken = preferences.getString(ShapewaysClient.OAUTH_TOKEN, null);
	oauthTokenSecret = preferences.getString(ShapewaysClient.OAUTH_TOKEN_SECRET, null);

	// https://code.google.com/p/oauth-signpost/wiki/GettingStarted
	consumer = new CommonsHttpOAuthConsumer(ShapewaysApplication.CONSUMER_KEY, ShapewaysApplication.CONSUMER_SECRET);
	consumer.setTokenWithSecret(oauthToken, oauthTokenSecret);
}
 
开发者ID:entertailion,项目名称:Android-Shapeways,代码行数:23,代码来源:ShapewaysClient.java

示例11: amzaSyncClient

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //导入方法依赖的package包/类
private AmzaSyncClient amzaSyncClient(AmzaSyncSenderConfig config) throws Exception {
    if (config.loopback) {
        return syncReceiver;
    } else {
        String consumerKey = StringUtils.trimToNull(config.oAuthConsumerKey);
        String consumerSecret = StringUtils.trimToNull(config.oAuthConsumerSecret);
        String consumerMethod = StringUtils.trimToNull(config.oAuthConsumerMethod);
        if (consumerKey == null || consumerSecret == null || consumerMethod == null) {
            throw new IllegalStateException("OAuth consumer has not been configured");
        }

        consumerMethod = consumerMethod.toLowerCase();
        if (!consumerMethod.equals("hmac") && !consumerMethod.equals("rsa")) {
            throw new IllegalStateException("OAuth consumer method must be one of HMAC or RSA");
        }

        String scheme = config.senderScheme;
        String host = config.senderHost;
        int port = config.senderPort;

        OAuthSigner authSigner = (request) -> {
            CommonsHttpOAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
            oAuthConsumer.setMessageSigner(new HmacSha1MessageSigner());
            oAuthConsumer.setTokenWithSecret(consumerKey, consumerSecret);
            return oAuthConsumer.sign(request);
        };

        HttpClient httpClient = HttpRequestHelperUtils.buildHttpClient(scheme.equals("https"),
            config.allowSelfSignedCerts,
            authSigner,
            host,
            port,
            syncConfig.getSyncSenderSocketTimeout());

        return new HttpAmzaSyncClient(httpClient,
            mapper,
            "/api/sync/v1/commit/rows",
            "/api/sync/v1/ensure/partition");
    }
}
 
开发者ID:jivesoftware,项目名称:amza,代码行数:41,代码来源:AmzaSyncSenders.java


注:本文中的oauth.signpost.commonshttp.CommonsHttpOAuthConsumer.setTokenWithSecret方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。