WSO2 IS 4.6.0 报错:Access token identifier is not present in the validation request

最近用client  向 IS判断access token是否合法,在使用编写代码测试时,发现OAuth2TokenValidationServiceStub.validate()一直失败。

代码如下:

                OAuth2TokenValidationServiceStub stub = null;
		String serviceURL = OAuth2ClientServlet.serverUrl + "OAuth2TokenValidationService";
		try {
			stub = new OAuth2TokenValidationServiceStub(null, serviceURL);
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		CarbonUtils.setBasicAccessSecurityHeaders(OAuth2ClientServlet.userName, OAuth2ClientServlet.password, true, stub._getServiceClient());
		ServiceClient client = stub._getServiceClient();
		Options options = client.getOptions();
		options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS);
		options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS);
		options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS);
		options.setCallTransportCleanup(true);
		options.setManageSession(true);
		
		OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
		oauthReq.setAccessToken(accessToken);
		oauthReq.setTokenType("bearer");
			
		try {

			bool resp = stub.validate(params);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		

后google,发现:http://stackoverflow.com/questions/20796574/oauth-validation-fails-for-valid-token-in-wso2-is-4-6


I faced the same problem with OAuth Mediator in Wso2 ESB 4.8.0 accessing Wso2 Identity Server 4.6.0 via Oauth2 validation web service. With Identity server 4.5.0 it works fine.The mediator code invokes the client stub passing the accessToken as plain string.

The error message returned by validation service is Access token identifier is not present in the validation request.

To answer your question you should use the bundle org.wso2.carbon.identity.oauth.stub in version 4.2.2. It defines a class org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO_OAuth2AccessToken which should be used as a parameter for the OAuth2TokenValidationRequestDTO.setAccessToken method. The dto object can the be used as parameter for the OAuth2TokenValidationServiceStub.validate method.

居然是版本问题!


所以:将代码修改为下面即可:


 OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
OAuth2TokenValidationRequestDTO_OAuth2AccessToken oauthReq_token 
				= new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();

oauthReq_token.setTokenType("bearer");
oauthReq_token.setIdentifier(accessToken);
oauthReq.setAccessToken(oauthReq_token);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值