本文整理汇总了Java中oauth.signpost.basic.DefaultOAuthConsumer类的典型用法代码示例。如果您正苦于以下问题:Java DefaultOAuthConsumer类的具体用法?Java DefaultOAuthConsumer怎么用?Java DefaultOAuthConsumer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultOAuthConsumer类属于oauth.signpost.basic包,在下文中一共展示了DefaultOAuthConsumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createOAuthConsumer
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的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: OAuthConnector
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的package包/类
public OAuthConnector(OAuthServer server) {
logger.entry(server);
if (server == null) {
throw new IllegalArgumentException("Server must not be null.");
}
logger.debug("new OAuthconn");
this.mServer = server;
this.mConsumer = new DefaultOAuthConsumer(server.getConsumerKey(), server.getConsumerSecret());
String accessToken = mServer.getAccessToken();
String accessTokenSecret = mServer.getAccessTokenSecret();
if (accessToken != null || accessTokenSecret != null) {
this.mConsumer.setTokenWithSecret(accessToken, accessTokenSecret);
isAuthorized = true;
}
logger.exit(server);
}
示例3: getOAuthUri
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的package包/类
private static final String getOAuthUri(String uri, List<NameValuePair> params, String key, String secret) {
final OAuthConsumer consumer = new DefaultOAuthConsumer(key, secret);
HttpParameters additionalParameters = new HttpParameters();
additionalParameters.put("oauth_timestamp", String.valueOf(getDate().getTime() / 1000));
consumer.setAdditionalParameters(additionalParameters);
try {
return consumer.sign(uri + "?" + URLEncodedUtils.format(params, "UTF-8"));
} catch (OAuthException e) {
try {
return uri + "web/error.html?message=" + URLEncoder.encode(e.getMessage(), "UTF-8");
} catch (UnsupportedEncodingException f) {
return uri + "web/error.html?message=Unknown%20Error";
}
}
}
示例4: processHttpMessage
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的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();
}
}
}
示例5: createOAuthConsumer
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的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;
}
示例6: makeRequest
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的package包/类
/**
* Makes a one-legged OAuth 1.0a request for the specified URL.
*
* @param url the URL being requested
* @return an HttpResponse
* @since 1.0.0
*/
private HttpResponse<JsonNode> makeRequest(String url) {
try {
final OAuthConsumer consumer = new DefaultOAuthConsumer(this.consumerKey, this.consumerSecret);
final String signed = consumer.sign(url);
return Unirest.get(signed).header("X-User-Agent", USER_AGENT).asJson();
} catch (OAuthException | UnirestException e) {
LOGGER.error("An error occurred making request: " + url, e);
}
return null;
}
示例7: retrieveRequestToken
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的package包/类
/**
* Request the request token and secret.
*
* @param callbackURL the URL where the provider should redirect to (usually a URL on the current app)
* @return A Right(RequestToken) in case of success, Left(OAuthException) otherwise
*/
public RequestToken retrieveRequestToken(String callbackURL) {
OAuthConsumer consumer = new DefaultOAuthConsumer(info.key.key, info.key.secret);
try {
provider.retrieveRequestToken(consumer, callbackURL);
return new RequestToken(consumer.getToken(), consumer.getTokenSecret());
} catch(OAuthException ex) {
throw new RuntimeException(ex);
}
}
示例8: retrieveAccessToken
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的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.basic.DefaultOAuthConsumer; //导入依赖的package包/类
private static OAuthConsumer createConsumerThatProhibitsEverything()
{
OAuthConsumer result = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
result.setTokenWithSecret(
"RCamNf4TT7uNeFjmigvOUWhajp5ERFZmcN1qvi7a",
"72dzmAvuNBEOVKkif3JSYdzMlAq2dw5OnIG75dtX");
return result;
}
示例10: createConsumerThatAllowsEverything
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的package包/类
private static OAuthConsumer createConsumerThatAllowsEverything()
{
OAuthConsumer result = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
result.setTokenWithSecret(
"2C4LiOQBOn96kXHyal7uzMJiqpCsiyDBvb8pomyX",
"1bFMIQpgmu5yjywt3kknopQpcRmwJ6snDDGF7kdr");
return result;
}
示例11: createOAuthConsumer
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的package包/类
private OAuthConsumer createOAuthConsumer() {
final OAuthConsumer consumer = new DefaultOAuthConsumer(client.getKey(), client.getSecret());
if (null != token) {
consumer.setTokenWithSecret(token.getToken(), token.getSecret());
}
return consumer;
}
示例12: signRequest
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的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);
}
}
示例13: createOAuthConsumer
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的package包/类
/**
* Creates an oauth consumer used for signing request URLs.
*
* @return The OAuthConsumer.
*/
public static OAuthConsumer createOAuthConsumer(String clientId, String clientSecret) {
OAuthConsumer consumer =
new DefaultOAuthConsumer(clientId, clientSecret);
consumer.setSigningStrategy(new QueryStringSigningStrategy());
return consumer;
}
示例14: prepare
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的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);
}
}
示例15: retrieveRequestToken
import oauth.signpost.basic.DefaultOAuthConsumer; //导入依赖的package包/类
/**
* Request the request token and secret.
* @param callbackURL the URL where the provider should redirect to
* @return a Response object holding either the result in case of a success or the error
*/
public Response retrieveRequestToken(String callbackURL) {
OAuthConsumer consumer = new DefaultOAuthConsumer(info.consumerKey, info.consumerSecret);
try {
provider.retrieveRequestToken(consumer, callbackURL);
} catch (OAuthException e) {
return Response.error(new Error(e));
}
return Response.success(consumer.getToken(), consumer.getTokenSecret());
}