本文整理匯總了Java中oauth.signpost.OAuthConsumer類的典型用法代碼示例。如果您正苦於以下問題:Java OAuthConsumer類的具體用法?Java OAuthConsumer怎麽用?Java OAuthConsumer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
OAuthConsumer類屬於oauth.signpost包,在下文中一共展示了OAuthConsumer類的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: onCreate
import oauth.signpost.OAuthConsumer; //導入依賴的package包/類
@Override public void onCreate(@Nullable Bundle inState)
{
super.onCreate(inState);
Injector.instance.getApplicationComponent().inject(this);
if(inState != null)
{
consumer = (OAuthConsumer) inState.getSerializable(CONSUMER);
state = State.valueOf(inState.getString(STATE));
}
else
{
consumer = consumerProvider.get();
state = State.INITIAL;
}
osmConnection = OsmModule.osmConnection(consumer);
}
示例3: saveConsumer
import oauth.signpost.OAuthConsumer; //導入依賴的package包/類
public void saveConsumer(OAuthConsumer consumer)
{
SharedPreferences.Editor editor = prefs.edit();
if(consumer != null)
{
editor.putString(Prefs.OAUTH_ACCESS_TOKEN, consumer.getToken());
editor.putString(Prefs.OAUTH_ACCESS_TOKEN_SECRET, consumer.getTokenSecret());
}
else
{
editor.remove(Prefs.OAUTH_ACCESS_TOKEN);
editor.remove(Prefs.OAUTH_ACCESS_TOKEN_SECRET);
}
editor.apply();
}
示例4: prepareConnection
import oauth.signpost.OAuthConsumer; //導入依賴的package包/類
private HttpURLConnection prepareConnection(OAuthConsumer consumer) {
final URL url = buildUrlFromUri();
final boolean useProxy = isProxySetInSystemProperties();
final HttpURLConnection req = openConnection(url, useProxy ? proxyFromSystemProperties() : null);
req.setDoOutput(null != body);
setRequestMethod(req);
for (final HttpHeader header : headers) {
req.addRequestProperty(header.getName(), header.getValue());
}
if (consumer != null) {
signRequestWithConsumer(req, consumer);
}
disableRedirectsSoTheyCanBeResignedWithOAuth(req);
if (useProxy) {
makeSslInsecureFor(req);
}
return req;
}
示例5: startAuthentication
import oauth.signpost.OAuthConsumer; //導入依賴的package包/類
/**
* Starts the OAuth authentication flow.
*/
public synchronized void startAuthentication(String accountId) {
WithingsAccount withingsAccount = getAccount(accountId);
if (withingsAccount == null) {
logger.warn("Couldn't find Credentials of Account '{}'. Please check openhab.cfg or withings.cfg.", accountId);
return;
}
OAuthConsumer consumer = withingsAccount.createConsumer();
provider = new DefaultOAuthProvider(OAUTH_REQUEST_TOKEN_ENDPOINT,
OAUTH_ACCESS_TOKEN_ENDPOINT_URL, OAUTH_AUTHORIZE_ENDPOINT_URL);
try {
String url = provider.retrieveRequestToken(consumer, this.redirectUrl);
printSetupInstructions(url);
} catch (OAuthException ex) {
logger.error(ex.getMessage(), ex);
printAuthenticationFailed(ex);
}
}
示例6: getOAuthUri
import oauth.signpost.OAuthConsumer; //導入依賴的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";
}
}
}
示例7: requestObjectApi
import oauth.signpost.OAuthConsumer; //導入依賴的package包/類
private static void requestObjectApi( OAuthConsumer consumer ) throws MalformedURLException, IOException, OAuthMessageSignerException,
OAuthExpectationFailedException, OAuthCommunicationException, UnsupportedEncodingException
{
LOGGER.info( "#################################################################################################" );
URL url =
new URL( "http://sandbox.immobilienscout24.de/restapi/api/search/v1.0/searcher/abc" );
HttpURLConnection apiRequest = (HttpURLConnection) url.openConnection();
consumer.sign( apiRequest );
LOGGER.info( "Sending request..." );
apiRequest.connect();
LOGGER.info( "Expiration "+apiRequest.getExpiration() );
LOGGER.info( "Timeout "+apiRequest.getConnectTimeout() );
LOGGER.info( "URL "+apiRequest.getURL() );
LOGGER.info( "Method "+apiRequest.getRequestMethod() );
LOGGER.info( "Response: "+apiRequest.getResponseCode()+" "
+apiRequest.getResponseMessage() );
LOGGER.info( "#################################################################################################" );
}
示例8: run
import oauth.signpost.OAuthConsumer; //導入依賴的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());
}
}
示例9: doPost
import oauth.signpost.OAuthConsumer; //導入依賴的package包/類
private JSONObject doPost(Account acct, URL url, JSONObject activity) throws Exception {
Log.i(TAG, "Posting " + activity);
OAuthConsumer cons = OAuth.getConsumerForAccount(getContext(), acct);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
cons.sign(conn);
OutputStream os = conn.getOutputStream();
OutputStreamWriter wr = new OutputStreamWriter(os);
wr.write(activity.toString());
wr.close();
if(conn.getResponseCode() != 200) {
Log.e(TAG, "Error posting: " + Utils.readAll(conn.getErrorStream()));
return null;
}
JSONObject result = new JSONObject(Utils.readAll(conn.getInputStream()));
return result;
}
示例10: 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;
}
示例11: 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();
}
}
}
示例12: 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);
}
}
示例13: startAuthentication
import oauth.signpost.OAuthConsumer; //導入依賴的package包/類
/**
* Starts the OAuth authentication flow.
*/
public synchronized void startAuthentication(String accountId) {
WithingsAccount withingsAccount = getAccount(accountId);
if (withingsAccount == null) {
logger.warn("Couldn't find Credentials of Account '{}'. Please check openhab.cfg or withings.cfg.",
accountId);
return;
}
OAuthConsumer consumer = withingsAccount.createConsumer();
provider = new DefaultOAuthProvider(OAUTH_REQUEST_TOKEN_ENDPOINT, OAUTH_ACCESS_TOKEN_ENDPOINT_URL,
OAUTH_AUTHORIZE_ENDPOINT_URL);
try {
String url = provider.retrieveRequestToken(consumer, this.redirectUrl);
printSetupInstructions(url);
} catch (OAuthException ex) {
logger.error(ex.getMessage(), ex);
printAuthenticationFailed(ex);
}
}
示例14: 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);
}
}
示例15: loadInBackground
import oauth.signpost.OAuthConsumer; //導入依賴的package包/類
@Override
public URL loadInBackground() {
NoteblurApplication app = (NoteblurApplication) getContext().getApplicationContext();
OAuthConsumer consumer = app.consumer;
OAuthProvider provider = app.provider;
try {
String authUrl = provider
.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
SharedPreferences prefs = getContext().getSharedPreferences("bob", 0);
prefs.edit().putString("TOKEN", consumer.getToken())
.putString("SECRET", consumer.getTokenSecret())
.commit();
return new URL(authUrl);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
throw new RuntimeException(e);
}
}