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


Java OAuthClient类代码示例

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


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

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

示例9: 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

示例10: doGetAuthenticationInfo

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

import org.apache.oltu.oauth2.client.OAuthClient; //导入依赖的package包/类
@Override
public Object getMetaInfo(OAuthToken token){
	try{
		OAuthClientRequest req = 
				new OAuthBearerClientRequest("https://www.googleapis.com/oauth2/v1/userinfo?alt=json")
        		   .setAccessToken(token.getAccessToken())
        		   .buildQueryMessage();
    	OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
    	OAuthResourceResponse resourceResponse = oAuthClient.resource(req, 
    											OAuth.HttpMethod.GET, OAuthResourceResponse.class);
    	ObjectMapper mapper = new ObjectMapper();
    	return mapper.readTree((resourceResponse.getBody()));
	}catch(Exception e){
		throw new RuntimeException(e);
	}
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:17,代码来源:GoogleProfileProvider.java

示例12: 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

示例13: OAuth

import org.apache.oltu.oauth2.client.OAuthClient; //导入依赖的package包/类
public OAuth( OkHttpClient client, TokenRequestBuilder requestBuilder ) {
    this.oauthClient = new OAuthClient(new OAuthOkHttpClient(client));
    this.tokenRequestBuilder = requestBuilder;
}
 
开发者ID:ARMmbed,项目名称:mbed-cloud-sdk-java,代码行数:5,代码来源:OAuth.java

示例14: getRolesTokenResponse

import org.apache.oltu.oauth2.client.OAuthClient; //导入依赖的package包/类
public String getRolesTokenResponse(String pathWithParams) throws WebApiClientException {
    String 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);
        result = resourceResponse.getBody();
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:15,代码来源:YpaWebApiJwtRiClient.java

示例15: 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


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