本文整理匯總了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);
};
}
示例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);
}
示例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);
}
示例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");
}
}
示例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");
}
}
示例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();
}
示例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);
}
示例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;
}
}
示例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;
}
示例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);
}
示例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");
}
}