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


Java OAuthClientRequest类代码示例

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


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

示例1: makeTokenRequestWithAuthCode

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的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: getPrincipals

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
@Override
public List<Principal> getPrincipals(String requestId) throws WebApiClientException {
    List<Principal> result = null;
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/delegate/" + getOauthSessionId(), requestId);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        JavaType resultType = mapper.getTypeFactory().constructParametricType(ArrayList.class, Principal.class);
        return mapper.readValue(resourceResponse.getBody(), resultType);
    } catch (IOException | OAuthSystemException | OAuthProblemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:20,代码来源:AbstractHpaWebApiRiClient.java

示例3: getAuthorization

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
@Override
public Authorization getAuthorization(String principalId, String requestId, String... issues)
        throws WebApiClientException {
    Authorization result = null;
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/authorization/" + getOauthSessionId() + "/" + principalId, requestId, issues);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        result = mapper.readValue(resourceResponse.getBody(), Authorization.class);
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:20,代码来源:HpaWebApiRiClient.java

示例4: getAuthorizationList

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
@Override
public AuthorizationList getAuthorizationList(String principalId, String requestId)
        throws WebApiClientException {
    AuthorizationList result = null;
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/authorizationlist/" + getOauthSessionId() + "/" + principalId, requestId);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        result = mapper.readValue(resourceResponse.getBody(), AuthorizationList.class);
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:20,代码来源:HpaWebApiRiClient.java

示例5: getAuthorizationToken

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
@Override
public String getAuthorizationToken(String principalId, String requestId, String... issues) throws WebApiClientException {
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/authorization/jwt/" + getOauthSessionId() + "/" + principalId, requestId, issues);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);
        return resourceResponse.getBody();
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    handleException(new WebApiClientException("Could not get Authorization token"));
    // should not get here
    return null;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:19,代码来源:HpaWebApiJwtRiClient.java

示例6: getAuthorizationListToken

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
@Override
public String getAuthorizationListToken(String principalId, String requestId) throws WebApiClientException {
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/authorizationlist/jwt/" + getOauthSessionId() + "/" + principalId, requestId);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        return resourceResponse.getBody();
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    handleException(new WebApiClientException("Could not get AuthorizationList token"));
    // should not get here
    return null;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:20,代码来源:HpaWebApiJwtRiClient.java

示例7: getRolesResponse

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
public List<YpaOrganization> getRolesResponse(String pathWithParams) throws WebApiClientException {
    List<YpaOrganization> result = null;
    OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
    try {
        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        JavaType resultType = mapper.getTypeFactory().constructParametricType(ArrayList.class, YpaOrganization.class);
        result = mapper.readValue(resourceResponse.getBody(), resultType);
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:17,代码来源:YpaWebApiRiClient.java

示例8: getToken

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

示例9: refreshOauthToken

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

示例10: doGetAuthenticationInfo

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
/**
 * authenticate through OAuth token URI
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
    throws AuthenticationException {
  OAuthClientToken clientToken = (OAuthClientToken) token;
  OAuthClient client = new OAuthClient(new CloseableHttpClient4());
  try {
    OAuthClientRequest oAuthRequest = OAuthClientRequest.tokenLocation(tokenURI)
        .setClientId(clientId).setClientSecret(clientSecret)
        .setGrantType(clientToken.getGrantType()).setCode(clientToken.getAuthCode())
        .setRefreshToken(clientToken.getRefreshToken()).setRedirectURI("client")
        .buildBodyMessage();
    return buildAuthenticationInfo(clientToken, client.accessToken(oAuthRequest));
  } catch (OAuthSystemException | OAuthProblemException ex) {
    throw new AuthenticationException(ex.getMessage(), ex);
  } finally {
    client.shutdown();
  }
}
 
开发者ID:hawkxu,项目名称:shiro-oltu,代码行数:22,代码来源:OAuthAuthorizeRealm.java

示例11: login

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
@GetMapping("/login")
public String login(HttpServletRequest request) {
    try {
        OAuthClientRequest oauthResponse = OAuthClientRequest
                .authorizationLocation(authorize_url)
                .setResponseType(OAuth.OAUTH_CODE)
                .setClientId(clientId)
                .setRedirectURI(server + OAUTH_WEIBO_CALLBACK)
                .setState(STATE_LOGIN)
                .buildQueryMessage();
        WebUtils.setSessionAttribute(request, "state", STATE_LOGIN);
        return "redirect:"+oauthResponse.getLocationUri();
    } catch (OAuthSystemException e) {
        e.printStackTrace();
    }

    return "redirect:/500";
}
 
开发者ID:microacup,项目名称:microbbs,代码行数:19,代码来源:WeiboOAuthClient.java

示例12: redirectToLogin

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
protected void redirectToLogin(HttpServletRequest request, HttpServletResponse response, String clientId) throws
        IOException {
    try {
        OAuthClientRequest oAuthRequest = OAuthClientRequest
                .authorizationLocation(AUTHORIZATION_LOCATION)
                .setClientId(clientId)
                .setRedirectURI(getRedirectUri(request))
                .setResponseType("code")
                .setScope(SCOPE)
                .setState(generateStateParam(request))
                .buildQueryMessage();
        liferay.debug("Redirecting to URL: " + oAuthRequest.getLocationUri());
        response.sendRedirect(oAuthRequest.getLocationUri());
    } catch (OAuthSystemException e) {
        throw new IOException("While redirecting to OP", e);
    }
}
 
开发者ID:finalist,项目名称:liferay-oidc-plugin,代码行数:18,代码来源:LibFilter.java

示例13: downloadUrl

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
private String downloadUrl() throws IOException { // we can probably return null
    InputStream is = null;
    String contentAsString = "";

    try {
        OAuthClientRequest.AuthenticationRequestBuilder requestBuilder = OAuthClientRequest.authorizationLocation(MainActivity.AUTHORIZATION_URL);
        requestBuilder.setClientId(GPXKeeperOAuthData.CLIENT_ID);
        requestBuilder.setResponseType("code");
        requestBuilder.setRedirectURI(GPX_KEEPER_URI);
        OAuthClientRequest request = requestBuilder.buildQueryMessage();
        Intent authenticate = new Intent(Intent.ACTION_VIEW, Uri.parse(request.getLocationUri()));
        startActivityForResult(authenticate, 0);
    } catch (OAuthSystemException e) {
        e.printStackTrace();
    } finally {
        if (is != null) {
            is.close();
        }
        return contentAsString;

    }
}
 
开发者ID:flooose,项目名称:gpxkept,代码行数:23,代码来源:MainActivity.java

示例14: send

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
public void send(Activity activity, String jSONBody) throws OAuthSystemException, OAuthProblemException {
    OAuthClientRequest bearerRequest = new OAuthBearerClientRequest(RUNKEEPER_API_URL + "/fitnessActivities")
            .setAccessToken(accessToken).buildQueryMessage();
    bearerRequest.setBody(jSONBody);
    bearerRequest.setHeader(OAuth.HeaderType.CONTENT_TYPE, NEW_ACTIVITY_CONTENT_TYPE);

    // Seems not to be needed although it's specified here: http://developer.runkeeper.com/healthgraph/example-api-calls
    //bearerRequest.setHeader("accept", "application/vnd.com.runkeeper.FitnessActivity+json");
    //bearerRequest.setHeader("Content-Length", "" + jSONBody.length());

    ConnectivityManager connMgr = (ConnectivityManager)
            activity.getSystemService(activity.getBaseContext().CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo != null && networkInfo.isConnected()) {
        FetchContent fetcher =  new FetchContent(bearerRequest);
        fetcher.execute(MainActivity.AUTHORIZATION_URL);
    } else { }
}
 
开发者ID:flooose,项目名称:gpxkept,代码行数:20,代码来源:RunKeeperRequest.java

示例15: deauthorize

import org.apache.oltu.oauth2.client.request.OAuthClientRequest; //导入依赖的package包/类
public void deauthorize(Activity activity){
    OAuthClientRequest bearerRequest = null;
    try {
        bearerRequest = new OAuthBearerClientRequest(RUNKEEPER_API_URL + "/apps/de-authorize")
                .setAccessToken(accessToken).buildQueryMessage();
        bearerRequest.setHeader(OAuth.HeaderType.CONTENT_TYPE, "application/x-www-form-urlencoded");
    } catch (OAuthSystemException e) {
        e.printStackTrace();
    }
    ConnectivityManager connMgr = (ConnectivityManager)
            activity.getSystemService(activity.getBaseContext().CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo != null && networkInfo.isConnected()) {
        FetchContent fetcher =  new FetchContent(bearerRequest);
        fetcher.execute(MainActivity.AUTHORIZATION_URL);
    } else { }
}
 
开发者ID:flooose,项目名称:gpxkept,代码行数:19,代码来源:RunKeeperRequest.java


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