[英]To access Published WSO2 API Manager APIs using tokens from WSO2 ESB, Unable to get the access token from WSO2 API Manager
I have written WSo2 ESB Proxy service where the proxy service calls the http service which is published in WSo2 API Manager. 我已经编写了WSo2 ESB代理服务,其中代理服务调用了在WSo2 API管理器中发布的http服务。 Because the API's are published in WSo2 API Manager to access the API we need to generate the token using a consumer key and a secret key. 由于API是在WSo2 API管理器中发布的以访问API,因此我们需要使用使用者密钥和秘密密钥来生成令牌。 I manually logged in to wso2 api manager, I subscribed to the published API and using my consumer key and secret key I have generated the token and use that token while calling the API from WSo2 ESB. 我手动登录到wso2 api管理器,我订阅了已发布的API,并使用我的使用者密钥和私有密钥生成了令牌,并在从WSo2 ESB调用API时使用了该令牌。 In the http request header I have set those token and from WSo2 ESB able to invoke the API getting response from the API, but this token will expire after 60 minutes so I need to generate the token by calling 在http请求标头中,我设置了那些令牌,并从WSo2 ESB设置了可以调用API的功能,以从API获取响应,但是此令牌将在60分钟后过期,因此我需要通过调用来生成令牌
https://api-dev.xyz.org/token
POST
Authorization: Basic Zzc5enNRN0xLM0hOcHU2N0g2a2R1dkx6WGRrYTpJSEF1NWZUdW5FdG9BV0xfa1hCcUdvRGVPWmdh
Payload
grant_type=client_credentials
I will get response as 我会得到回应
response
{
scope: "default"
token_type: "bearer"
expires_in: 3171
access_token: "db995950f960b4c67162e2d92a1117a5"
}
curl command to get the token:- curl命令获取令牌:-
curl -k -d "grant_type=client_credentials" -H "Authorization: Basic Rnl5YmwwNVhacGhBb01mVE5VNE91ZkxfblRVYTpUSmt6QUJFbzZaN3FkNkE1cHE3V3JSd2ZNaHNh, Content-Type: application/x-www-form-urlencoded" https://api-dev.xyz.org:8243/token
In WSo2 ESB Proxy Service i have coded similar to curl command to get the token, 在WSo2 ESB代理服务中,我已编写类似于curl命令的代码来获取令牌,
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Authorization"
expression="fn:concat('Basic ',OUU0Zk05eU81R0VCcV9odUxBYW15SzRCaEZFYToxVmVnbHl5OFBhQTkyMFRxbEUySnduWHlTbThh)"
scope="transport"/>
<payloadFactory media-type="json">
<format>
{
"grant_type":"client_credentials"
}
</format>
</payloadFactory>
<property name="messageType" value="application/x-www-form-urlencoded" scope="axis2"/>
<send>
<endpoint>
<http method="get" uri-template="https://api-dev.xyz.org:8243/token"/>
<property name="grant_type" value="client_credentials"/>
</endpoint>
</send>
I'm getting response as 我得到回应
TargetHandler I/O error: Host name verification failed for host : 172.18.65.251
javax.net.ssl.SSLException: Host name verification failed for host : 172.18.65.251
at org.apache.synapse.transport.http.conn.ClientSSLSetupHandler.verify(ClientSSLSetupHandler.java:162)
at org.apache.http.nio.reactor.ssl.SSLIOSession.doHandshake(SSLIOSession.java:291)
at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:391)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:119)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:159)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:338)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:316)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:277)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:105)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:586)
at java.lang.Thread.run(Thread.java:745)
Any idea how to resolve this issue ? 任何想法如何解决这个问题?
This is a certificate validation issue. 这是证书验证问题。 This happens when the server can't find a corresponding certificate for the host. 当服务器找不到主机的相应证书时,就会发生这种情况。 You can try one of the following methods to fix this: 您可以尝试以下方法之一来解决此问题:
eg: 例如:
<transportSender name="https" class="org.apache.synapse.transport.passthru.PassThroughHttpSSLSender">
....
<parameter name="HostnameVerifier">AllowAll</parameter>
....
</transportSender>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.