當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。