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


Java OAuthAccessTokenResponse类代码示例

本文整理汇总了Java中org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse的典型用法代码示例。如果您正苦于以下问题:Java OAuthAccessTokenResponse类的具体用法?Java OAuthAccessTokenResponse怎么用?Java OAuthAccessTokenResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OAuthAccessTokenResponse类属于org.apache.oltu.oauth2.client.response包,在下文中一共展示了OAuthAccessTokenResponse类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeTokenRequestWithAuthCode

import org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse; //导入依赖的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: buildAuthenticationInfo

import org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse; //导入依赖的package包/类
/**
 * create authentication info, by default, this create
 * SimpleAuthenticationInfo with principals using access token as primary
 * principal and a map contains attributes {@link OAuth#OAUTH_ACCESS_TOKEN}
 * and {@link OAuth#OAUTH_EXPIRES_IN} and {@link OAuth#OAUTH_REFRESH_TOKEN}
 * and {@link OAuthConstants#OAUTH_TOKEN_TIME} and
 * {@link OAuthConstants#OAUTH_SCOPES}, the credentials set to byte array of
 * access token. if sub-class override requestAttributes and returned
 * attributes contains key {@link OAuthConstants#OAUTH_PRINCIPAL}, then the
 * value will be used as primary principal.
 * 
 * @param clientToken
 *          the client token
 * @param oAuthResponse
 *          OAuth access token response
 * @return authentication info
 */
protected AuthenticationInfo buildAuthenticationInfo(OAuthClientToken clientToken,
    OAuthAccessTokenResponse oAuthResponse) {
  String accessToken = oAuthResponse.getAccessToken();
  Date tokenTime = new Date();
  Map<String, Object> attributes = requestAttributes(oAuthResponse);
  if (attributes == null)
    attributes = new HashMap<String, Object>();
  else
    attributes = new HashMap<String, Object>(attributes);
  List<Object> principals = new ArrayList<Object>();
  if (attributes.containsKey(OAuthConstants.OAUTH_PRINCIPAL))
    principals.add(attributes.get(OAuthConstants.OAUTH_PRINCIPAL));
  else
    principals.add(accessToken);
  attributes.put(OAuth.OAUTH_ACCESS_TOKEN, accessToken);
  attributes.put(OAuth.OAUTH_EXPIRES_IN, oAuthResponse.getExpiresIn());
  attributes.put(OAuth.OAUTH_REFRESH_TOKEN, oAuthResponse.getRefreshToken());
  attributes.put(OAuthConstants.OAUTH_TOKEN_TIME, tokenTime);
  attributes.put(OAuthConstants.OAUTH_SCOPES, clientToken.getScopes());
  principals.add(attributes);
  PrincipalCollection collection = new SimplePrincipalCollection(principals, getName());
  return new SimpleAuthenticationInfo(collection, accessToken);
}
 
开发者ID:hawkxu,项目名称:shiro-oltu,代码行数:41,代码来源:OAuthAuthorizeRealm.java

示例3: getAccessToken

import org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse; //导入依赖的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

示例4: getAccessTokenResponse

import org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse; //导入依赖的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

示例5: requestAttributes

import org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse; //导入依赖的package包/类
/**
 * sub-class should override this method to request principal attributes,
 * these attributes will put as Subject second principal in type Map. Note
 * {@link OAuth#OAUTH_ACCESS_TOKEN} and {@link OAuth#OAUTH_EXPIRES_IN} and
 * {@link OAuth#OAUTH_REFRESH_TOKEN} and
 * {@link OAuthConstants#OAUTH_TOKEN_TIME} and
 * {@link OAuthConstants#OAUTH_SCOPES} will be put later, so do not use those
 * five keys.
 * 
 * @param oAuthResponse
 *          OAuth access token response
 * @return principal attributes, if the returned attributes contains key
 *         <b>principal</b>, then the value will be used as Subject primary
 *         principal
 */
protected Map<String, Object> requestAttributes(OAuthAccessTokenResponse oAuthResponse) {
  return null;
}
 
开发者ID:hawkxu,项目名称:shiro-oltu,代码行数:19,代码来源:OAuthAuthorizeRealm.java


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