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

WBOY
发布: 2016-06-07 15:39:09
原创
1447 人浏览过

最近用client 向 IS判断access token是否合法,在使用编写代码测试时,发现OAuth2TokenValidationServiceStub.validate()一直失败。 代码如下: OAuth2TokenValidationServiceStub stub = null;String serviceURL = OAuth2ClientServlet.serverUrl + OAuth2T

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

代码如下:

<span>                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();
		}
		
		</span>
登录后复制

后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.

居然是版本问题!


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


<span> OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
OAuth2TokenValidationRequestDTO_OAuth2AccessToken oauthReq_token 
				= new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();

oauthReq_token.setTokenType("bearer");
oauthReq_token.setIdentifier(accessToken);
oauthReq.setAccessToken(oauthReq_token);</span>
登录后复制



相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板