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


Java Token類代碼示例

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


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

示例1: redirectUserToGrantAccess

import org.scribe.model.Token; //導入依賴的package包/類
@Override
protected String redirectUserToGrantAccess()
{
    try
    {
        OAuthService service = createOAuthScribeService();
        Token requestToken = service.getRequestToken();
        String authUrl = service.getAuthorizationUrl(requestToken);

        request.getSession().setAttribute("requestToken", requestToken);

        return SystemUtils.getRedirect(this, authUrl, true);

    } catch (Exception e)
    {
        addErrorMessage("Cannot proceed authentication, check OAuth credentials for account " + getOrganizationName());
        return INPUT;
    }
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:20,代碼來源:RegenerateBitbucketOauthToken.java

示例2: getAccessTokenExtractor

import org.scribe.model.Token; //導入依賴的package包/類
@Override
public AccessTokenExtractor getAccessTokenExtractor() {
    return new AccessTokenExtractor() {
        
        @Override
        public Token extract(String response) {
            Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");

            Matcher matcher = Pattern.compile("\"access_token\" : \"([^&\"]+)\"").matcher(response);
            if (matcher.find())
            {
              String token = OAuthEncoder.decode(matcher.group(1));
              return new Token(token, "", response);
            } 
            else
            {
              throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
            }
        }
    };
}
 
開發者ID:elimu-ai,項目名稱:webapp,代碼行數:22,代碼來源:Google2Api.java

示例3: getAccessToken

import org.scribe.model.Token; //導入依賴的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: getAccessTokenExtractor

import org.scribe.model.Token; //導入依賴的package包/類
@Override
public AccessTokenExtractor getAccessTokenExtractor() {
    return new AccessTokenExtractor() {
        
        @Override
        public Token extract(String response) {
        	
            Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
            
            // We are not interested in access_token - we and the JWT encrypted token
            // Matcher matcher = Pattern.compile("\"access_token\" : \"([^&\"]+)\"").matcher(response);
            Matcher matcher = Pattern.compile("\"id_token\" : \"([^&\"]+)\"").matcher(response);
            if (matcher.find()) {
            	String token = OAuthEncoder.decode(matcher.group(1));
            	return new Token(token, "", response);
            } else {
            	throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
            }
        }
    };
}
 
開發者ID:tahamsaglam,項目名稱:duckdns,代碼行數:22,代碼來源:Google2Api.java

示例5: getAccessToken

import org.scribe.model.Token; //導入依賴的package包/類
@Override
protected String getAccessToken()
{
    Verifier verifier = new Verifier(request.getParameter("oauth_verifier"));
    Token requestToken = (Token) request.getSession().getAttribute("requestToken");
    request.getSession().removeAttribute("requestToken");

    OAuthService service = createOAuthScribeService();
    Token accessTokenObj = null;
    try
    {
        accessTokenObj = service.getAccessToken(requestToken, verifier);
    } catch (OAuthConnectionException e)
    {
        Organization organizationInstance = organizationService.get(Integer.parseInt(organization), false);
        throw new SourceControlException("Error obtaining access token. Cannot access " + organizationInstance.getHostUrl() + " from Jira.", e);
    } finally
    {
        httpClientProvider.closeIdleConnections();
    }

    return BitbucketOAuthAuthentication.generateAccessTokenString(accessTokenObj);
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:24,代碼來源:RegenerateBitbucketOauthToken.java

示例6: doFinish

import org.scribe.model.Token; //導入依賴的package包/類
public String doFinish()
{
    // now get the access token
    Verifier verifier = new Verifier(request.getParameter("oauth_verifier"));
    Token requestToken = (Token) request.getSession().getAttribute(SESSION_KEY_REQUEST_TOKEN);

    if (requestToken == null)
    {
        log.debug("Request token is NULL. It has been removed in the previous attempt of adding organization. Now we will stop.");
        return getRedirect("ConfigureDvcsOrganizations.jspa?atl_token=" + CustomStringUtils.encode(getXsrfToken()));
    }

    request.getSession().removeAttribute(SESSION_KEY_REQUEST_TOKEN);

    OAuthService service = createOAuthScribeService();
    Token accessTokenObj = service.getAccessToken(requestToken, verifier);
    accessToken = BitbucketOAuthAuthentication.generateAccessTokenString(accessTokenObj);

    httpClientProvider.closeIdleConnections();

    return doAddOrganization();
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:23,代碼來源:AddBitbucketOrganization.java

示例7: getRequestToken

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

  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...");
  HttpClientOauthResponse response = request.sendViaHttpClient();
  String body = response.getContent();

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

示例8: oAuth

import org.scribe.model.Token; //導入依賴的package包/類
private void oAuth() {
    // Replace these with your own api key and secret
    OAuthService service = FlickrForPalabreApplication.getoAuthService();
    Token mRequestToken = FlickrForPalabreApplication.getRequestToken();

    if (mRequestToken == null) {
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(MainActivity.this, getString(R.string.oauth_connection_error), Toast.LENGTH_LONG).show();
            }
        });
        return;
    }

    final String authorizationUrl = service.getAuthorizationUrl(mRequestToken);
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
    editor.putString(SharedPreferenceKeys.TOKEN_TOKEN, mRequestToken.getToken())
            .putString(SharedPreferenceKeys.TOKEN_SECRET, mRequestToken.getSecret())
            .putString(SharedPreferenceKeys.TOKEN_RESPONSE, mRequestToken.getRawResponse())
            .apply();

    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authorizationUrl)));

}
 
開發者ID:levelup,項目名稱:palabre-extensions,代碼行數:26,代碼來源:MainActivity.java

示例9: getClusterRoles

import org.scribe.model.Token; //導入依賴的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

示例10: executeScript

import org.scribe.model.Token; //導入依賴的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

示例11: getClusterParams

import org.scribe.model.Token; //導入依賴的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

示例12: setClusterParam

import org.scribe.model.Token; //導入依賴的package包/類
/**
 * 設置集群參數, 若之前無此參數,則添加; 若有則替換
 * 
 * @param clusterId
 *            集群ID
 * @param name
 *            集群參數名稱
 * @param value
 *            集群參數值
 * @return
 * @throws Fit2CloudException
 */
public boolean setClusterParam(long clusterId, String name, String value) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/cluster/" + clusterId + "/param");
	request.addBodyParameter("name", name);
	request.addBodyParameter("value", value);
	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 "true".equals(responseString);
	} else {
		throw new Fit2CloudException(response.getBody());
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:29,代碼來源:Fit2CloudClient.java

示例13: addScript

import org.scribe.model.Token; //導入依賴的package包/類
/**
 * 添加腳本
 * 
 * @param name
 *            腳本名稱
 * @param description
 *            腳本描述
 * @param scriptText
 *            腳本內容
 * @return 腳本ID
 * @throws Fit2CloudException
 */
public Long addScript(String name, String description, String scriptText) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/script/add");
	request.addBodyParameter("name", name);
	request.addBodyParameter("description", description);
	request.addBodyParameter("scriptText", scriptText);
	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(response.getBody());
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:30,代碼來源:Fit2CloudClient.java

示例14: editScript

import org.scribe.model.Token; //導入依賴的package包/類
/**
 * 編輯指定腳本
 * 
 * @param scriptId
 *            腳本ID
 * @param description
 *            腳本描述
 * @param scriptText
 *            腳本內容
 * @return
 * @throws Fit2CloudException
 */
public boolean editScript(long scriptId, String description, String scriptText) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/script/" + scriptId + "/update");
	request.addBodyParameter("description", description);
	request.addBodyParameter("scriptText", scriptText);
	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 "true".equals(responseString);
	} else {
		throw new Fit2CloudException(response.getBody());
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:29,代碼來源:Fit2CloudClient.java

示例15: saveTag

import org.scribe.model.Token; //導入依賴的package包/類
/**
 * 給指定虛機設置標簽. 若無則新增標簽; 若有則替換
 * 
 * @param serverId
 *            虛機ID
 * @param tagName
 *            標簽名稱
 * @param tagValue
 *            標簽值
 * @return
 * @throws Fit2CloudException
 */
public Tag saveTag(Long serverId, String tagName, String tagValue) throws Fit2CloudException {
	OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/tags/save");
	if (serverId != null && serverId.intValue() > 0) {
		request.addBodyParameter("serverId", String.valueOf(serverId));
	}
	if (tagName != null && tagName.trim().length() > 0) {
		request.addBodyParameter("tagName", tagName.trim());
	}
	if (tagValue != null && tagValue.trim().length() > 0) {
		request.addBodyParameter("tagValue", tagValue.trim());
	}
	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 new GsonBuilder().create().fromJson(responseString, Tag.class);
	} else {
		throw new Fit2CloudException(response.getBody());
	}
}
 
開發者ID:fit2cloud,項目名稱:fit2cloud-general-java-sdk,代碼行數:36,代碼來源:Fit2CloudClient.java


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