本文整理匯總了Java中oauth.signpost.commonshttp.CommonsHttpOAuthConsumer類的典型用法代碼示例。如果您正苦於以下問題:Java CommonsHttpOAuthConsumer類的具體用法?Java CommonsHttpOAuthConsumer怎麽用?Java CommonsHttpOAuthConsumer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CommonsHttpOAuthConsumer類屬於oauth.signpost.commonshttp包,在下文中一共展示了CommonsHttpOAuthConsumer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sign
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
@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;
}
示例2: buildReplaceResult
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
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;
}
示例3: 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);
};
}
示例4: Twitter_Handler
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
public Twitter_Handler(Activity context, String consumerKey,
String secretKey) {
this.context = context;
twitterObj = new TwitterFactory().getInstance();
mSession = new TwitterSession(context);
mProgressDlg = new ProgressDialog(context);
mProgressDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
mConsumerKey = consumerKey;
mSecretKey = secretKey;
mHttpOauthConsumer = new CommonsHttpOAuthConsumer(mConsumerKey,mSecretKey);
String request_url = TWITTER_REQUEST_URL;
String access_token_url = TWITTER_ACCESS_TOKEN_URL;
String authorize_url = TWITTER_AUTHORZE_URL;
mHttpOauthprovider = new DefaultOAuthProvider(request_url,
access_token_url, authorize_url);
mAccessToken = mSession.getAccessToken();
configureToken();
}
示例5: getMockedClient
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
private OAuthClient getMockedClient() throws Exception {
when(properties.getProperty("consumerKey")).thenReturn("key");
when(properties.getProperty("consumerSecret")).thenReturn("secret");
final FileInputStream fileInputStreamMock = PowerMockito.mock(FileInputStream.class);
PowerMockito.whenNew(FileInputStream.class).withArguments(Matchers.anyString())
.thenReturn(fileInputStreamMock);
PowerMockito.whenNew(CommonsHttpOAuthConsumer.class).withArguments(Matchers.anyString(), Matchers.anyString())
.thenReturn(CommonsHttpOAuthConsumerMock);
PowerMockito.whenNew(CommonsHttpOAuthProvider.class).withArguments(Matchers.anyString(), Matchers.anyString(), Matchers.anyString())
.thenReturn(CommonsHttpOAuthProviderMock);
Config config = new Config(properties);
OAuthClient client = new OAuthClient(config);
return client;
}
示例6: doInBackground
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
@Override
protected String doInBackground(String... params){
try{
this.consumer = new CommonsHttpOAuthConsumer(myConstants.CONDUCTTR_CONSUMER_KEY,
myConstants.CONDUCTTR_CONSUMER_SECRET);
this.consumer.setTokenWithSecret(myConstants.CONDUCTTR_ACCESS_TOKEN, myConstants.CONDUCTTR_ACCESS_TOKEN_SECRET);
String url = myConstants.CONDUCTTR_BASE_URL + myConstants.CONDUCTTR_PROJECT_ID + "/" ;
HttpPost request = new HttpPost(url);
List<NameValuePair> params1 = new ArrayList<NameValuePair>();
params1.add(new BasicNameValuePair("audience_phone", audience_phone.getText().toString() ));
request.setEntity(new UrlEncodedFormEntity(params1));
consumer.sign(request);
HttpClient httpClient = new DefaultHttpClient();
//HttpResponse response = httpClient.execute(request);
httpClient.execute(request);
}
catch(Exception e){
e.printStackTrace();
resp = e.getMessage();
}
return resp;
}
示例7: doInBackground
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
@Override
protected String doInBackground(String... params){
try{
this.consumer = new CommonsHttpOAuthConsumer(myConstants.CONDUCTTR_CONSUMER_KEY,
myConstants.CONDUCTTR_CONSUMER_SECRET);
this.consumer.setTokenWithSecret(myConstants.CONDUCTTR_ACCESS_TOKEN, myConstants.CONDUCTTR_ACCESS_TOKEN_SECRET);
String url = myConstants.CONDUCTTR_BASE_URL + myConstants.CONDUCTTR_PROJECT_ID + "/registration" ;
HttpPost request = new HttpPost(url);
List<NameValuePair> params1 = new ArrayList<NameValuePair>();
params1.add(new BasicNameValuePair("audience_phone", audience_phone.getText().toString() ));
request.setEntity(new UrlEncodedFormEntity(params1));
consumer.sign(request);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
resp="okidoki";
}
catch(Exception e){
e.printStackTrace();
resp = e.getMessage();
}
return resp;
}
示例8: ToopherAPI
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
/**
* Create an API object with the supplied credentials, overriding the default API URI of https://api.toopher.com/v1/
*
* @param consumerKey
* The consumer key for a requester (obtained from the developer portal)
* @param consumerSecret
* The consumer secret for a requester (obtained from the developer portal)
* @param uri
* The alternate URI
*/
public ToopherAPI(String consumerKey, String consumerSecret, URI uri) {
httpClient = new DefaultHttpClient();
HttpProtocolParams.setUserAgent(httpClient.getParams(),
String.format("ToopherJava/%s", VERSION));
consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
if (uri == null) {
this.uriScheme = ToopherAPI.DEFAULT_URI_SCHEME;
this.uriHost = ToopherAPI.DEFAULT_URI_HOST;
this.uriPort = ToopherAPI.DEFAULT_URI_PORT;
this.uriBase = ToopherAPI.DEFAULT_URI_BASE;
} else {
this.uriScheme = uri.getScheme();
this.uriHost = uri.getHost();
this.uriPort = uri.getPort();
this.uriBase = uri.getPath();
}
}
示例9: 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);
}
示例10: TwitterApp
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
private TwitterApp(Context context, String consumerKey, String secretKey) {
this.context = context;
mTwitter = new TwitterFactory().getInstance();
mSession = new TwitterSession(context);
mProgressDlg = new ProgressDialog(context);
mProgressDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
mConsumerKey = consumerKey;
mSecretKey = secretKey;
mHttpOauthConsumer = new CommonsHttpOAuthConsumer(mConsumerKey, mSecretKey);
mHttpOauthprovider = new DefaultOAuthProvider("https://api.twitter.com/oauth/request_token ",
"https://api.twitter.com/oauth/access_token",
"https://api.twitter.com/oauth/authorize");
mAccessToken = mSession.getAccessToken();
configureToken();
}
示例11: run
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
public void run() {
JSONObject statement = buildStatement();
LTIConsumer consumer = user.getConsumer();
String key = consumer.getKey().toString();
String secret = consumer.getSecret().toString();
OAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
try {
HttpPost request = new HttpPost(user.getXapiUrl());
request.setHeader("Content-Type", "application/json");
request.setEntity(new StringEntity(statement.toString(), "UTF-8"));
signer.sign(request);
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() >= 400) {
throw new Exception(response.getStatusLine().getReasonPhrase());
}
} catch (Exception e) {
MinecraftLTI.instance.getLogger().warning("Failed to send duration: "+e.getMessage());
}
}
示例12: onCreate
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
System.setProperty("debug", "true");
this.consumer = new CommonsHttpOAuthConsumer(OAuthConstants.CONSUMER_KEY, OAuthConstants.CONSUMER_SECRET);
this.provider = new CommonsHttpOAuthProvider(
OAuthConstants.REQUEST_URL + "?scope=" + URLEncoder.encode(OAuthConstants.SCOPE, OAuthConstants.ENCODING),
OAuthConstants.ACCESS_URL + "?scope=" + URLEncoder.encode(OAuthConstants.SCOPE, OAuthConstants.ENCODING),
OAuthConstants.AUTHORIZE_URL);
} catch (Exception e) {
Log.e(TAG, "Error creating consumer / provider",e);
}
Log.i(TAG, "Starting task to retrieve request token.");
new OAuthRequestTokenTask(this,consumer,provider).execute();
}
示例13: doOAuth
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
public void doOAuth() {
try {
OAuthConsumer consumer = new CommonsHttpOAuthConsumer(ShapewaysApplication.CONSUMER_KEY, ShapewaysApplication.CONSUMER_SECRET);
consumer.setTokenWithSecret(((ShapewaysApplication) getApplicationContext()).getShapewaysClient().getOauthToken(),
((ShapewaysApplication) getApplicationContext()).getShapewaysClient().getOauthTokenSecret());
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e68
HttpGet request = new HttpGet(ShapewaysClient.API_URL_BASE + ShapewaysClient.API_PATH);
consumer.sign(request);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
Log.d(LOG_TAG, "response=" + response.getStatusLine());
Log.d(LOG_TAG, "response=" + EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
Log.e(LOG_TAG, "doOAuth", e);
}
}
示例14: onCreate
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//設置屏幕沒有標題欄
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.welcome);
webInstance = this;
mContext = getApplicationContext();
accessInfo = InfoHelper.getAccessInfo(mContext);
//生成consumer,consumer代表我們自己開發的應用JSU
consumer = new CommonsHttpOAuthConsumer(ConstantsUtils.CONSUMER_KEY,
ConstantsUtils.CONSUMER_SECRET);
//生成provider,provider代表新浪微博,傳入認證需要的三個地址
provider = new DefaultOAuthProvider(
UrlUtils.REQUEST_TOKEN,
UrlUtils.ACCESS_TOKEN,
UrlUtils.AUTHORIZE);
}
示例15: IOSTwitterAPI
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; //導入依賴的package包/類
public IOSTwitterAPI(TwitterConfig config) {
super(config);
consumer = new CommonsHttpOAuthConsumer(config.TWITTER_CONSUMER_KEY, config.TWITTER_CONSUMER_SECRET);
provider = new CommonsHttpOAuthProvider("https://api.twitter.com/oauth/request_token", "https://api.twitter.com/oauth/access_token",
"https://api.twitter.com/oauth/authorize");
}