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


Java OAuthClient.accessToken方法代码示例

本文整理汇总了Java中org.apache.oltu.oauth2.client.OAuthClient.accessToken方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthClient.accessToken方法的具体用法?Java OAuthClient.accessToken怎么用?Java OAuthClient.accessToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.oltu.oauth2.client.OAuthClient的用法示例。


在下文中一共展示了OAuthClient.accessToken方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeTokenRequestWithAuthCode

import org.apache.oltu.oauth2.client.OAuthClient; //导入方法依赖的package包/类
/**
    * 根据授权码获取accessToken
    * @param authCode
    * @return
    * @throws OAuthProblemException
    * @throws OAuthSystemException
    */
private static OAuthAccessTokenResponse makeTokenRequestWithAuthCode(String authCode) throws OAuthProblemException, OAuthSystemException {

       OAuthClientRequest request = OAuthClientRequest
               .tokenLocation(ClientParams.OAUTH_SERVER_TOKEN_URL)
               .setClientId(ClientParams.CLIENT_ID)
               .setClientSecret(ClientParams.CLIENT_SECRET)
               .setGrantType(GrantType.AUTHORIZATION_CODE)
               .setCode(authCode)
               .setRedirectURI(ClientParams.OAUTH_SERVER_REDIRECT_URI)
               .buildBodyMessage();

       OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

       OAuthAccessTokenResponse oauthResponse = oAuthClient.accessToken(request);

       System.out.println("Access Token: " + oauthResponse.getAccessToken());
       System.out.println("Expires In: " + oauthResponse.getExpiresIn());

       getAuthedService(oauthResponse.getAccessToken());

       return oauthResponse;
   }
 
开发者ID:xiaomin0322,项目名称:oauth_demo,代码行数:30,代码来源:OauthClient.java

示例2: getToken

import org.apache.oltu.oauth2.client.OAuthClient; //导入方法依赖的package包/类
public void getToken(String codeParam, String stateParam) throws WebApiClientException {
    if (!stateParameter.equals(stateParam)) {
        clientActiveState = false;
        throw new WebApiClientException("Mismatching OAuth state parameter. Expected state=" + stateParameter);
    }

    OAuthJSONAccessTokenResponse oAuthResponse = null;
    try {
        OAuthClientRequest.TokenRequestBuilder requestBuilder = OAuthClientRequest.tokenLocation(config.getTokenUrl()).setGrantType(GrantType.AUTHORIZATION_CODE).setClientId(config.getClientId()).setClientSecret(config.getoAuthSecret()).setCode(codeParam);

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        oAuthResponse = oAuthClient.accessToken(requestBuilder.setRedirectURI(config.getoAuthRedirect()).buildBodyMessage(), OAuthJSONAccessTokenResponse.class);
    } catch (OAuthProblemException | OAuthSystemException e) {
        handleException("Unable to get token", e);
    }
    this.accessToken = oAuthResponse.getAccessToken();
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:18,代码来源:AbstractWebApiRiClient.java

示例3: refreshOauthToken

import org.apache.oltu.oauth2.client.OAuthClient; //导入方法依赖的package包/类
/**
 * Method to refresh oauth token.
 * 
 * @param refreshToken
 *            requires a refresh token.
 * 
 * @param apiKey
 *            requires valid api key.
 * 
 * @param secret
 *            requires a valid secret.
 * 
 * @return OAuthJSONAccessTokenResponse object.
 * 
 * @throws ClientException
 *             a client exception is thrown if any error occurs.
 */
public OAuthJSONAccessTokenResponse refreshOauthToken(String refreshToken, String apiKey, String secret)
		throws ClientException {
	String oauthTokenUrl = tOneService.constructOauthUrl(new StringBuilder(TOKEN));
	try {
		OAuthClientRequest request = OAuthClientRequest.tokenLocation(oauthTokenUrl)
				.setGrantType(GrantType.REFRESH_TOKEN).setClientId(apiKey).setClientSecret(secret)
				.setRefreshToken(refreshToken).buildQueryMessage();
		OAuthClient oauthClient = new OAuthClient(new URLConnectionClient());
		return oauthClient.accessToken(request, OAuthJSONAccessTokenResponse.class);
	} catch (OAuthSystemException oauthSystemException) {
		Utility.logStackTrace(oauthSystemException);
		throw new ClientException(UNABLE_TO_GET_O_AUTH_TOKEN + oauthSystemException.getMessage());
	} catch (OAuthProblemException oauthProblemException) {
		Utility.logStackTrace(oauthProblemException);
		throw new ClientException(UNABLE_TO_GET_O_AUTH_TOKEN + oauthProblemException.getMessage());
	}
}
 
开发者ID:MediaMath,项目名称:t1-java,代码行数:35,代码来源:TerminalOne.java

示例4: getAccessToken

import org.apache.oltu.oauth2.client.OAuthClient; //导入方法依赖的package包/类
@RequestMapping(value = "/token/{channel}", method = RequestMethod.GET)
public ModelAndView getAccessToken(@PathVariable String channel, Model model, 
		HttpServletRequest req) throws Exception {
	
	OpenAPI openAPI = dispatcher.dispatch(channel);
	OpenAPIConfig config = openAPI.getOpenAPIConfig();
	
	OAuthAuthzResponse res = OAuthAuthzResponse.oauthCodeAuthzResponse(req);
	
	OAuthClientRequest request = OAuthClientRequest
			.tokenLocation(config.getTokenUrl())
			.setClientId(config.getAppkey())
			.setClientSecret(config.getAppSecret())
			.setRedirectURI(config.getRedirectUri())
			.setCode(res.getCode())
			.setGrantType(GrantType.AUTHORIZATION_CODE)
			.buildBodyMessage();
	
	OAuthClient client = new OAuthClient(new SSLURLConnectionClient());
	
	OAuthJSONAccessTokenResponse response = client.accessToken(request, OAuthJSONAccessTokenResponse.class);
	
	openAPI.convertResponseToAccessToken(response);
	
	return new ModelAndView("redirect:/index.html");
}
 
开发者ID:colddew,项目名称:mix-web,代码行数:27,代码来源:OpenAPIAction.java

示例5: getAccessToken

import org.apache.oltu.oauth2.client.OAuthClient; //导入方法依赖的package包/类
@Override
public OAuthToken getAccessToken(String code, String callback) throws OAuthSystemException, OAuthProblemException{
	OAuthClientRequest request = OAuthClientRequest
               .tokenLocation(getAccessTokenEndpoint())
               .setGrantType(GrantType.AUTHORIZATION_CODE)
               .setClientId(getApiKey())
               .setClientSecret(getApiSecret())
               .setRedirectURI(callback)
               .setCode(code)
               .buildBodyMessage();

   	OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
   	OAuthJSONAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request);
       return oAuthResponse.getOAuthToken();
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:16,代码来源:OAuth20Provider.java

示例6: login

import org.apache.oltu.oauth2.client.OAuthClient; //导入方法依赖的package包/类
@Authenticate
public static String login(String serverId, String code, String locales, String redirectBase)
{
  try
  {
    String redirect = redirectBase + "/session/ologin";
    
    OauthServer server = OauthServer.get(serverId);
    /*
     * Get the access token
     */
    TokenRequestBuilder tokenBuilder = OAuthClientRequest.tokenLocation(server.getTokenLocation());
    tokenBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
    tokenBuilder.setClientId(server.getClientId());
    tokenBuilder.setClientSecret(server.getSecretKey());
    tokenBuilder.setRedirectURI(redirect);
    tokenBuilder.setCode(code);
    
    OAuthClientRequest tokenRequest = tokenBuilder.buildQueryMessage();
    tokenRequest.setHeader("Accept", "application/json");
    
    oAuthClient = new OAuthClient(new URLConnectionClient());
    accessToken = oAuthClient.accessToken(tokenRequest);
    
    /*
     * Request the user information
     */
    JSONObject object = resourceRequest(server.getProfileLocation());

    SingleActorDAOIF profile = ExternalProfile.getOrCreate(server, object);

    return SessionFacade.logIn(profile, LocaleSerializer.deserialize(locales));
  }
  catch (JSONException | OAuthSystemException | OAuthProblemException e)
  {
    throw new InvalidLoginException(e);
  }
}
 
开发者ID:terraframe,项目名称:geoprism,代码行数:39,代码来源:ExternalProfile.java

示例7: getAccessToken

import org.apache.oltu.oauth2.client.OAuthClient; //导入方法依赖的package包/类
/**
 * Request an access token from trakt. Builds the request with {@link #getAccessTokenRequest(String, String, String,
 * String)} and executes it, then returns the response which includes the access token.
 *
 * <p> Supply the received access token to {@link #setAccessToken(String)}.
 *
 * <p> On failure re-authorization of your app is required (see {@link #getAuthorizationRequest(String, String,
 * String, String)}).
 *
 * @param clientId The OAuth client id obtained from trakt.
 * @param clientSecret The OAuth client secret obtained from trakt.
 * @param redirectUri The redirect URI previously used for obtaining the auth code.
 * @param authCode A valid authorization code (see {@link #getAuthorizationRequest(String, String, String,
 * String)}).
 */
public static OAuthAccessTokenResponse getAccessToken(String clientId, String clientSecret, String redirectUri,
        String authCode) throws OAuthSystemException, OAuthProblemException {
    OAuthClientRequest request = getAccessTokenRequest(clientId, clientSecret, redirectUri, authCode);

    OAuthClient client = new OAuthClient(new TraktHttpClient());
    return client.accessToken(request);
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:23,代码来源:TraktV2.java

示例8: getAccessTokenResponse

import org.apache.oltu.oauth2.client.OAuthClient; //导入方法依赖的package包/类
/**
 * Request an access token from tvtag. Builds the request with {@link #getAccessTokenRequest(String, String, String,
 * String)} and executes it, then returns the response which includes the access and refresh tokens.
 *
 * @param clientId The OAuth client id obtained from tvtag.
 * @param clientSecret The OAuth client secret obtained from tvtag.
 * @param redirectUri The redirect URI previously used for obtaining the auth code.
 * @param authCode A previously obtained auth code.
 * @return A new OAuth access and refresh token from tvtag.
 * @throws OAuthSystemException
 * @throws OAuthProblemException
 */
public static OAuthAccessTokenResponse getAccessTokenResponse(String clientId,
        String clientSecret, String redirectUri, String authCode)
        throws OAuthSystemException, OAuthProblemException {
    OAuthClientRequest request = getAccessTokenRequest(clientId, clientSecret, redirectUri, authCode);

    // create HTTP client which is able to follow protocol redirects (tvtag likes to redirect from HTTPS to HTTP)
    OAuthClient client = new OAuthClient(new GetGlueHttpClient());
    return client.accessToken(request);
}
 
开发者ID:UweTrottmann,项目名称:getglue-java,代码行数:22,代码来源:GetGlue.java


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