當前位置: 首頁>>代碼示例>>Java>>正文


Java OAuthRequest類代碼示例

本文整理匯總了Java中org.scribe.model.OAuthRequest的典型用法代碼示例。如果您正苦於以下問題:Java OAuthRequest類的具體用法?Java OAuthRequest怎麽用?Java OAuthRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OAuthRequest類屬於org.scribe.model包,在下文中一共展示了OAuthRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: send

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
private String send(Verb verb, String params) throws Exception {
    String url = apiUrl + ((params != null) ? params : "");
    
    OAuthRequest request = new OAuthRequest(verb, url);
    request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, apiAccessToken);
    
    // For more details on the “Bearer” token refer to http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-23
    StringBuilder sb = new StringBuilder();
    sb.append("Bearer ");
    sb.append(apiAccessToken);
    request.addHeader("Authorization",  sb.toString());

    if (LOG.isDebugEnabled()) {
        LOG.debug("Yammer request url: {}", request.getCompleteUrl());
    }
    
    Response response = request.send();
    if (response.isSuccessful()) {                    
        return response.getBody();
    } else {
        throw new Exception(String.format("Failed to poll %s. Got response code %s and body: %s", getApiUrl(), response.getCode(), response.getBody()));
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:ScribeApiRequestor.java

示例2: appendSignature

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
private void appendSignature(OAuthRequest request)
{
  switch (config.getSignatureType())
  {
    case Header:
      config.log("using Http Header signature");

      String oauthHeader = api.getHeaderExtractor().extract(request);
      request.addHeader(OAuthConstants.HEADER, oauthHeader);
      break;
    case QueryString:
      config.log("using Querystring signature");

      for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
      {
        request.addQuerystringParameter(entry.getKey(), entry.getValue());
      }
      break;
  }
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:21,代碼來源:HttpClientThrreeLoOAuth10aServiceImpl.java

示例3: getAccessToken

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    switch (api.getAccessTokenVerb()) {
    case POST:
        request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
        request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
        request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
        request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
        request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_AUTHORIZATION_CODE);
        break;
    case GET:
    default:
        request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
        request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
        request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
        request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
        if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
    }
    Response response = request.send();
    return api.getAccessTokenExtractor().extract(response.getBody());
}
 
開發者ID:elimu-ai,項目名稱:webapp,代碼行數:23,代碼來源:Google2Api.java

示例4: afterFinalUriConstructed

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
@Override
protected String afterFinalUriConstructed(HttpRequestBase forMethod, String finalUri, Map<String, ? extends Object> parameters)
{
    long start = System.currentTimeMillis();
	//
	// generate oauth 1.0 params for 2LO - use scribe so far for that ...
	//
	OAuthService service = createOauthService();
	OAuthRequest request = new OAuthRequest(Verb.valueOf(forMethod.getMethod()), finalUri);

	addParametersForSigning(request, parameters);

	service.signRequest(new EmptyToken(), request);
	Map<String, String> oauthParams = request.getOauthParameters();
	//
	//
	log.debug("2LO signing took [{}] ms ", System.currentTimeMillis() - start);

	return finalUri + paramsToString(oauthParams, finalUri.indexOf("?") != -1);
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:21,代碼來源:TwoLegged10aOauthRemoteRequestor.java

示例5: addParametersForSigning

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
protected void addParametersForSigning(final OAuthRequest request, final Map<String, ? extends Object> parameters)
{
    if (parameters == null)
    {
        return;
    }
    Verb method = request.getVerb();
    if (method == Verb.POST || method == Verb.PUT)
    {
        processParams(parameters, new ParameterProcessor()
        {
            @Override
            public void process(String key, String value)
            {
                request.addBodyParameter(key, value);
            }

        });
    }
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:21,代碼來源:ScribeOauthRemoteRequestor.java

示例6: getRequestToken

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public Token getRequestToken()
{
	config.log("obtaining request token from " + api.getRequestTokenEndpoint());
	OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint());

	config.log("setting oauth_callback to " + config.getCallback());
	request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback());
	addOAuthParams(request, OAuthConstants.EMPTY_TOKEN);
	appendSignature(request);

	config.log("sending request...");
	Response response = request.send();
	String body = response.getBody();

	config.log("response status code: " + response.getCode());
	config.log("response body: " + body);
	return api.getRequestTokenExtractor().extract(body);
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:23,代碼來源:TwoLoOAuth10aServiceImpl.java

示例7: appendSignature

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
private void appendSignature(OAuthRequest request)
{
	switch (config.getSignatureType())
	{
	case Header:
		config.log("using Http Header signature");

		String oauthHeader = api.getHeaderExtractor().extract(request);
		request.addHeader(OAuthConstants.HEADER, oauthHeader);
		break;
	case QueryString:
		config.log("using Querystring signature");

		for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
		{
			request.addQuerystringParameter(entry.getKey(), entry.getValue());
		}
		break;
	}
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:21,代碼來源:TwoLoOAuth10aServiceImpl.java

示例8: onConnectionCreated

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
@Override
protected void onConnectionCreated(HttpClient client, HttpRequestBase method, Map<String, ? extends Object> parameters)
        throws IOException
{
    long start = System.currentTimeMillis();
    //
    // generate oauth 1.0 params for 3LO - use scribe so far for that ...
    //
    OAuthService service = createOauthService();
    OAuthRequest request = new OAuthRequest(Verb.valueOf(method.getMethod()), method.getURI().toString());

    addParametersForSigning(request, parameters);

    service.signRequest(generateAccessTokenObject(accessTokenWithSecret), request);

    String header = authHeaderCreator.extract(request);
    method.addHeader(OAuthConstants.HEADER, header);

    log.debug("3LO signing took [{}] ms ", System.currentTimeMillis() - start);
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:21,代碼來源:ThreeLegged10aOauthRemoteRequestor.java

示例9: getClusters

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
/**
 * 獲取當前用戶所有集群信息
 * 
 * @return
 * @throws Fit2CloudException
 */
public List<Cluster> getClusters() throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/clusters");
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		Type listType = new TypeToken<ArrayList<Cluster>>() {
		}.getType();
		return new GsonBuilder().create().fromJson(responseString, listType);
	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:22,代碼來源:Fit2CloudClient.java

示例10: getClusterRoles

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
/**
 * 獲取指定集群下所有虛機組信息
 * 
 * @param clusterId
 *            集群ID
 * @return
 * @throws Fit2CloudException
 */
public List<ClusterRole> getClusterRoles(long clusterId) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/cluster/" + clusterId + "/roles");
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		Type listType = new TypeToken<ArrayList<ClusterRole>>() {
		}.getType();
		return new GsonBuilder().create().fromJson(responseString, listType);
	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:24,代碼來源:Fit2CloudClient.java

示例11: executeScript

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
/**
 * 在指定虛機上執行指定腳本
 * 
 * @param serverId
 *            虛機ID
 * @param scriptContent
 *            腳本內容
 * @return 返回執行腳本事件ID, 可根據此ID獲取返回的所有執行日誌
 * @throws Fit2CloudException
 */
public long executeScript(long serverId, String scriptContent) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, executeScriptInServerUrl);
	request.addBodyParameter("serverId", String.valueOf(serverId));
	request.addBodyParameter("scriptContent", scriptContent);
	request.setCharset("UTF-8");
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		return Long.parseLong(responseString);
	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:27,代碼來源:Fit2CloudClient.java

示例12: getLoggingsByEventId

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
/**
 * 獲取事件返回的所有日誌信息(如執行腳本事件)
 * 
 * @param eventId
 *            事件ID
 * @return
 * @throws Fit2CloudException
 */
public List<Logging> getLoggingsByEventId(long eventId) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.GET, getLoggingUrl + eventId);
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		Type listType = new TypeToken<ArrayList<Logging>>() {
		}.getType();
		return new GsonBuilder().create().fromJson(responseString, listType);
	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:24,代碼來源:Fit2CloudClient.java

示例13: launchServer

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
/**
 * 創建虛機
 * 
 * @param clusterId
 *            虛機所在的集群
 * @param clusterRoleId
 *            虛機所在的虛機組
 * @param launchConfigurationId
 *            創建虛機所使用的模板
 * @return 創建後的虛機信息
 * @throws Fit2CloudException
 */
public Server launchServer(long clusterId, long clusterRoleId, long launchConfigurationId)
		throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/launchserver/cluster/" + clusterId
			+ "/clusterrole/" + clusterRoleId + "?launchConfigurationId=" + launchConfigurationId);
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		return new GsonBuilder().create().fromJson(responseString, Server.class);
	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:28,代碼來源:Fit2CloudClient.java

示例14: launchServerAsync

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
/**
 * 創建虛機. 此接口將立刻返回虛機ID,而後台將異步創建虛機. 之後通過返回的虛機信息中的ID來查詢完整的虛機信息
 * 
 * @param clusterId
 *            虛機所在的集群
 * @param clusterRoleId
 *            虛機所在的虛機組
 * @param launchConfigurationId
 *            創建虛機所使用的模板
 * @return
 * @throws Fit2CloudException
 */
public Server launchServerAsync(long clusterId, long clusterRoleId, long launchConfigurationId)
		throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/launchserver/async/cluster/" + clusterId
			+ "/clusterrole/" + clusterRoleId + "?launchConfigurationId=" + launchConfigurationId);
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		return new GsonBuilder().create().fromJson(responseString, Server.class);
	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:28,代碼來源:Fit2CloudClient.java

示例15: getClusterParams

import org.scribe.model.OAuthRequest; //導入依賴的package包/類
/**
 * 獲取指定集群的集群參數
 * 
 * @param clusterId
 *            集群ID
 * @return
 * @throws Fit2CloudException
 */
public List<ClusterParam> getClusterParams(long clusterId) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/cluster/" + clusterId + "/params");
	Token accessToken = new Token("", "");
	service.signRequest(accessToken, request);
	Response response = request.send();
	int code = response.getCode();
	String responseString = response.getBody();
	if (code == 200) {
		Type listType = new TypeToken<ArrayList<ClusterParam>>() {
		}.getType();
		return new GsonBuilder().create().fromJson(responseString, listType);

	} else {
		throw new Fit2CloudException(responseString);
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:25,代碼來源:Fit2CloudClient.java


注:本文中的org.scribe.model.OAuthRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。