当前位置: 首页>>代码示例>>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;未经允许,请勿转载。