Search in sources :

Example 1 with EcBaseOauthResourceResponse

use of com.easy.cloud.core.oauth.client.base.response.token.EcBaseOauthResourceResponse in project dq-easy-cloud by dq-open-cloud.

the class EcBaseOauthToken method doGetOauthResource.

/**
 * <p>
 * 执行获取授权资源信息
 * </p>
 * <pre>
 *     子类可以通过重写该方法实现自己的获取授权资源数据传输对象的数据
 * </pre>
 *
 * @param oAuthResponseParam
 * @return com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO
 * @author daiqi
 * @date 2018/7/18 11:54
 */
public EcBaseOauthResourceDTO doGetOauthResource(Map<String, Object> oAuthResponseParam) throws Exception {
    // 获取资源请求构建者
    EcBaseResourceRequestBuilder resourceRequestBuilder = getResourceRequestBuilder();
    // 构建客户端请求参数
    OAuthClientRequest resourceRequest = resourceRequestBuilder.buildClientRequest(oAuthResponseParam);
    // 执行请求资源
    EcBaseOauthResourceResponse resourceResponse = oAuthClient.resource(resourceRequest, OAuth.HttpMethod.GET, resourceRequestBuilder.getResourceResponseClass());
    // 从资源响应对象中获取资源数据传输对象
    EcBaseOauthResourceDTO resourceDTO = resourceResponse.getResourceObj(resourceResponse.getResourceDTOClass());
    EcLogUtils.info("授权获取到的用户信息", resourceDTO, logger);
    return resourceDTO;
}
Also used : EcBaseOauthResourceResponse(com.easy.cloud.core.oauth.client.base.response.token.EcBaseOauthResourceResponse) EcBaseResourceRequestBuilder(com.easy.cloud.core.oauth.client.base.request.builder.EcBaseResourceRequestBuilder) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest) EcBaseOauthResourceDTO(com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO)

Example 2 with EcBaseOauthResourceResponse

use of com.easy.cloud.core.oauth.client.base.response.token.EcBaseOauthResourceResponse in project dq-easy-cloud by dq-open-cloud.

the class EcZfbOauthToken method doGetOauthResource.

@Override
public EcBaseOauthResourceDTO doGetOauthResource(Map<String, Object> oAuthResponseParam) throws Exception {
    AlipayUserInfoShareRequest userInfoShareRequest = new AlipayUserInfoShareRequest();
    String accessToken = EcMapUtils.getString(oAuthResponseParam, EcOauthAccessToken.ACCESS_TOKEN);
    AlipayUserInfoShareResponse shareResponse = alipayClient.execute(userInfoShareRequest, accessToken);
    EcAssert.verifyObjNull(shareResponse, "shareResponse");
    if (shareResponse != null && shareResponse.isSuccess()) {
        EcBaseOauthResourceResponse resourceResponse = EcBeanFactory.newInstance(getResourceRequestBuilder().getResourceResponseClass());
        EcBaseOauthResourceDTO resourceDTO = EcJSONUtils.parseObject(shareResponse, resourceResponse.getResourceDTOClass());
        EcLogUtils.info("授权获取到的用户信息", resourceDTO, logger);
        return resourceDTO;
    } else {
        throw new EcBaseBusinessException(shareResponse.getCode(), shareResponse.getMsg()).buildExceptionDetail(shareResponse);
    }
}
Also used : EcBaseOauthResourceResponse(com.easy.cloud.core.oauth.client.base.response.token.EcBaseOauthResourceResponse) AlipayUserInfoShareRequest(com.alipay.api.request.AlipayUserInfoShareRequest) AlipayUserInfoShareResponse(com.alipay.api.response.AlipayUserInfoShareResponse) EcBaseBusinessException(com.easy.cloud.core.exception.bo.EcBaseBusinessException) EcBaseOauthResourceDTO(com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO)

Aggregations

EcBaseOauthResourceDTO (com.easy.cloud.core.oauth.client.base.pojo.dto.EcBaseOauthResourceDTO)2 EcBaseOauthResourceResponse (com.easy.cloud.core.oauth.client.base.response.token.EcBaseOauthResourceResponse)2 AlipayUserInfoShareRequest (com.alipay.api.request.AlipayUserInfoShareRequest)1 AlipayUserInfoShareResponse (com.alipay.api.response.AlipayUserInfoShareResponse)1 EcBaseBusinessException (com.easy.cloud.core.exception.bo.EcBaseBusinessException)1 EcBaseResourceRequestBuilder (com.easy.cloud.core.oauth.client.base.request.builder.EcBaseResourceRequestBuilder)1 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)1