当前位置: 首页>>代码示例>>Java>>正文


Java OAuthConsumer类代码示例

本文整理汇总了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;
	}
}
 
开发者ID:westnordost,项目名称:osmapi,代码行数:20,代码来源:OsmConnection.java

示例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);
}
 
开发者ID:westnordost,项目名称:StreetComplete,代码行数:18,代码来源:OsmOAuthDialogFragment.java

示例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();
}
 
开发者ID:westnordost,项目名称:StreetComplete,代码行数:18,代码来源:OAuthPrefs.java

示例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;
}
 
开发者ID:JohnDeere,项目名称:MyJohnDeereAPI-OAuth-Java-Client,代码行数:25,代码来源:RestRequest.java

示例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);
	}

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:WithingsAuthenticator.java

示例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";
        }
    }
}
 
开发者ID:toopher,项目名称:toopher-pingfederate,代码行数:17,代码来源:ToopherIframe.java

示例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( "#################################################################################################" );
}
 
开发者ID:OpenEstate,项目名称:OpenEstate-IS24-REST,代码行数:26,代码来源:IS24OauthExample.java

示例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());
  }
}
 
开发者ID:instructure,项目名称:MinecraftLTI,代码行数:23,代码来源:DurationRunner.java

示例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;
}
 
开发者ID:erincandescent,项目名称:Impeller,代码行数:26,代码来源:FeedSyncAdapter.java

示例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;
}
 
开发者ID:Ccook,项目名称:conniption,代码行数:22,代码来源:StreamingMarketQuote.java

示例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();
		}
	}
}
 
开发者ID:dnet,项目名称:burp-oauth,代码行数:19,代码来源:BurpExtender.java

示例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);
	}
}
 
开发者ID:entertailion,项目名称:Android-Shapeways,代码行数:21,代码来源:MainActivity.java

示例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);
    }

}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:27,代码来源:WithingsAuthenticator.java

示例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);
    }
}
 
开发者ID:Mapzen-POI-Collector,项目名称:Mapzen-Android,代码行数:24,代码来源:OsmConnection.java

示例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);
	}

}
 
开发者ID:secondsun,项目名称:devnexus2013demo,代码行数:24,代码来源:OAuthFetcherLoader.java


注:本文中的oauth.signpost.OAuthConsumer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。