本文整理汇总了Java中oauth.signpost.OAuthConsumer.setTokenWithSecret方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthConsumer.setTokenWithSecret方法的具体用法?Java OAuthConsumer.setTokenWithSecret怎么用?Java OAuthConsumer.setTokenWithSecret使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth.signpost.OAuthConsumer
的用法示例。
在下文中一共展示了OAuthConsumer.setTokenWithSecret方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createOAuthConsumer
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
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;
}
}
示例2: stream
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
public ContentExchange stream(ContentExchange ex, Symbol... symbols) throws ModelException
{
OAuthConsumer consumer = new JettyOAuthConsumer(ForemanConstants.API_KEY.toString(), ForemanConstants.API_SECRET.toString());
consumer.setTokenWithSecret(ForemanConstants.ACCESS_TOKEN.toString(), ForemanConstants.ACCESS_TOKEN_SECRET.toString());
ex.setMethod(Verb.GET.name());
ex.setURL(APICall.getStreamingQuote(ResponseFormat.XML) + getParameters(symbols));
// sign the request
try
{
consumer.sign(ex);
client.send(ex);
}
catch (IOException | OAuthMessageSignerException | OAuthExpectationFailedException | OAuthCommunicationException e)
{
throw new ModelException("Sent Exchange to Client", e);
}
return ex;
}
示例3: processHttpMessage
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
@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();
}
}
}
示例4: doOAuth
import oauth.signpost.OAuthConsumer; //导入方法依赖的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);
}
}
示例5: addOAuthAuthorizationHeader
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
/**
* Signs the connection with an OAuth authentication header
*
* @param connection the connection
*
* @throws OsmTransferException thrown if there is currently no OAuth Access Token configured
* @throws OsmTransferException thrown if signing fails
*/
protected void addOAuthAuthorizationHeader(HttpURLConnection connection) throws OsmTransferException {
if (oauthParameters == null) {
oauthParameters = OAuthParameters.createDefault();
}
OAuthConsumer consumer = oauthParameters.buildDefaultConsumer();
OAuthAccessTokenHolder holder = OAuthAccessTokenHolder.getInstance();
if (! holder.containsAccessToken())
throw new MissingOAuthAccessTokenException();
consumer.setTokenWithSecret(holder.getAccessTokenKey(), holder.getAccessTokenSecret());
try {
consumer.sign(connection);
} catch(OAuthException e) {
throw new OsmTransferException("Failed to sign a HTTP connection with an OAuth Authentication header", e);
}
}
示例6: loadConsumer
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
public static OAuthConsumer loadConsumer(SharedPreferences prefs) {
OAuthConsumer result = createConsumer();
String accessToken = prefs.getString(Prefs.OAUTH_ACCESS_TOKEN, null);
String accessTokenSecret = prefs.getString(Prefs.OAUTH_ACCESS_TOKEN_SECRET, null);
result.setTokenWithSecret(accessToken, accessTokenSecret);
return result;
}
示例7: createOAuthConsumer
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
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;
}
示例8: retrieveAccessToken
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
/**
* Exchange a request token for an access token.
*
* @param token the token/secret pair obtained from a previous call
* @param verifier a string you got through your user, with redirection
* @return A Right(RequestToken) in case of success, Left(OAuthException) otherwise
*/
public RequestToken retrieveAccessToken(RequestToken token, String verifier) {
OAuthConsumer consumer = new DefaultOAuthConsumer(info.key.key, info.key.secret);
consumer.setTokenWithSecret(token.token, token.secret);
try {
provider.retrieveAccessToken(consumer, verifier);
return new RequestToken(consumer.getToken(), consumer.getTokenSecret());
} catch (OAuthException ex) {
throw new RuntimeException(ex);
}
}
示例9: createConsumerThatProhibitsEverything
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
private static OAuthConsumer createConsumerThatProhibitsEverything()
{
OAuthConsumer result = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
result.setTokenWithSecret(
"RCamNf4TT7uNeFjmigvOUWhajp5ERFZmcN1qvi7a",
"72dzmAvuNBEOVKkif3JSYdzMlAq2dw5OnIG75dtX");
return result;
}
示例10: createConsumerThatAllowsEverything
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
private static OAuthConsumer createConsumerThatAllowsEverything()
{
OAuthConsumer result = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
result.setTokenWithSecret(
"2C4LiOQBOn96kXHyal7uzMJiqpCsiyDBvb8pomyX",
"1bFMIQpgmu5yjywt3kknopQpcRmwJ6snDDGF7kdr");
return result;
}
示例11: loadConsumer
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
public OAuthConsumer loadConsumer()
{
OAuthConsumer result = oAuthConsumerProvider.get();
String accessToken = prefs.getString(Prefs.OAUTH_ACCESS_TOKEN, null);
String accessTokenSecret = prefs.getString(Prefs.OAUTH_ACCESS_TOKEN_SECRET, null);
result.setTokenWithSecret(accessToken, accessTokenSecret);
return result;
}
示例12: createOAuthConsumer
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
private OAuthConsumer createOAuthConsumer() {
final OAuthConsumer consumer = new DefaultOAuthConsumer(client.getKey(), client.getSecret());
if (null != token) {
consumer.setTokenWithSecret(token.getToken(), token.getSecret());
}
return consumer;
}
示例13: doInBackground
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
@Override
protected RestResult doInBackground(String... args) {
try {
request = createRequest();
if (isCancelled())
throw new InterruptedException();
OAuthConsumer consumer = Session.getInstance().getOAuthConsumer();
if (consumer != null) {
AccessToken accessToken = Session.getInstance().getAccessToken();
if (accessToken != null) {
consumer.setTokenWithSecret(accessToken.getKey(), accessToken.getSecret());
}
consumer.sign(request);
}
request.setHeader("Accept-Language", Locale.getDefault().getLanguage());
request.setHeader("API-Client", String.format("uservoice-android-%s", UserVoice.getVersion()));
AndroidHttpClient client = AndroidHttpClient.newInstance(String.format("uservoice-android-%s", UserVoice.getVersion()), Session.getInstance().getContext());
if (isCancelled())
throw new InterruptedException();
// TODO it would be nice to find a way to abort the request on cancellation
HttpResponse response = client.execute(request);
if (isCancelled())
throw new InterruptedException();
HttpEntity responseEntity = response.getEntity();
StatusLine responseStatus = response.getStatusLine();
int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;
String body = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
client.close();
if (isCancelled())
throw new InterruptedException();
return new RestResult(statusCode, new JSONObject(body));
} catch (Exception e) {
return new RestResult(e);
}
}
示例14: signRequest
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
@Override
public void signRequest(HttpURLConnection apiRequest) {
OAuthConsumer consumer = new DefaultOAuthConsumer(apiConsumerKey, apiConsumerSecret);
consumer.setTokenWithSecret(accessToken, accessSecret);
try {
consumer.sign(apiRequest);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例15: prepare
import oauth.signpost.OAuthConsumer; //导入方法依赖的package包/类
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);
}
}