使用 wso2 esb 获得认知 acces_token

getting cognito acces_token with wso2 esb

我正在尝试使用客户端凭据通过 AWS Cognito 获取访问令牌,但得到了其他东西。

I'm doing this in wso2 Enterprise integrator 6.1.0

<payloadFactory media-type="xml">
    <format>
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema/instance">
            <soapenv:Header>
                <Content-Type xmlns=""></Content-Type>
                <Authorization xmlns=""></Authorization>
            </soapenv:Header>
            <soapenv:Body/>
        </soapenv:Envelope>
    </format>
    <args>
        <arg evaluator="xml" value="application/x-www-form-urlencoded"/>
        <arg value="Basic 2354sdfmdtrerkdfdgkeryryrtwdasr345345twsdfwsedtr34"/>
    </args>
</payloadFactory>
<log level="full"/>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
    <endpoint key="validateUser-ext-ep"/>
</call>
<log level="full"/>

after this the response i'm getting is like this :

 <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
    <soapenv:Body>
        <ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbiYWNrZ3JvdW5kLWN1c3RvbWl6YWJsZSBtb2RhbC1jb250ZW50LW1vYmlsZSI+CiAgICAgICAgICAgICAgICA8ZGl2PgogICAgICAgICAgICAgICAgICAgIDxkaXYgY2xhc3M9ImJhbm5lci1jdXN0b21pemFibGUiPgogICAgICAgICAgICAgICAgICAgICAgICA8Y2VudGVyPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgIDwvY2VudGVyPgogICAgICAgICAgICAgICAgICAgIDwvZGl2PgogICAgICAgICAgICAgICAgPC9kaXY+CiAgICAgICAgICAgICAgICA8ZGl2IGNsYXNzPSJtb2RhbC1ib2R5Ij4KICAgICAgICAgICAgICAgICAgICA8cCBhbGlnbj0iY2VudGVyIj5BbiBlcnJvciB3YXMgZW5jb3VudGVyZWQgd2l0aCB0aGUgcmVxdWVzdGVkIHBhZ2UuPC9wPgogICAgICAgICAgICAgICAgICAgIDxicj4KICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIDwvZGl2PgogICAgICAgICAgICA8L2Rpdj4KICAgICAgICA8L2Rpdj4KICAgIDwvZGl2Pgo8L2JvZHk+Cgo8L2h0bWw+Cg==</ns:binary>l
    </soapenv:Body>
</soapenv:Envelope>

我不知道我是否做错了邮递员 我发送数据的方式与我在那里获取令牌的方式相同 我将 Authrization 作为 Basic dfudne4r49859dfnw34598sdfs base64 endcoded(client :client_secret) 和 Content-Type : application/x-www-form-urlencoded 在 header 和参数中我通过了 grant_type: client_credential 为此我能够获得令牌但是当我在 wso2 esb 中尝试时我得到了上述错误 端点看起来像:https://xxxxxxxxxx.us-east-1.amazoncognito.com/oauth2/token?grant_type=client_credentials

this is the API to get the Access token and it returns the access token

<?xml version="1.0" encoding="UTF-8"?>
<api context="/api/myService" name="my-service-api" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST" uri-template="/getToken">
        <inSequence>
            <script language="js"><![CDATA[var payload = mc.getPayloadXML();
                var log = mc.getServiceLog();
                var client_id = payload..*::client_id.toString();
                var client_secret = payload..*::client_secret.toString();
                mc.setProperty("client_id", client_id);
                mc.setProperty("client_secret", client_secret);]]>
            </script>
            <payloadFactory media-type="json">
                <format/>
                <args/>
            </payloadFactory>
            <property name="ContentType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded"/>
            <property expression="fn:concat($ctx:client_id,':',$ctx:client_secret)" name="credentials" scope="default" type="STRING"/>
            <property expression="fn:concat('Basic ', base64Encode($ctx:credentials))" name="Authorization" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
            <property name="FORCE_POST_PUT_NOBODY" scope="axis2" type="BOOLEAN" value="true"/>
            <property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
            <call>
                <endpoint>
                    <http method="post" uri-template="https://xxxxxxxxxxx.amazoncognito.com/oauth2/token?grant_type=client_credentials"/>
                </endpoint>
            </call>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

Call the above API like this :

<payloadFactory media-type="xml">
    <format>
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <soapenv:Header/>
            <soapenv:Body>
                <root>
                    <client_id></client_id>
                    <client_secret></client_secret>
                </root>
            </soapenv:Body>
        </soapenv:Envelope>
    </format>
    <args>
        <arg evaluator="xml" expression="get-property('client_id')"/>
        <arg evaluator="xml" expression="get-property('client_secret')"/>
    </args>
</payloadFactory>
<property name="ContentType" scope="default" type="STRING" value="application/xml"/>
<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
<call>
    <endpoint>
        <http method="post" uri-template="http://localhost:8280/api/myService/getToken"/>
    </endpoint>
</call>
<script language="js">
    <![CDATA[ var tokenContainer = mc.getPayloadJSON();
        var log = mc.getServiceLog();
        mc.setProperty("Authorization_header", tokenContainer.access_token);]]>      
</script>

The Response will be

{"access_token":"LzSq94JoaUT2LwJlkEl35CXX0MdwqtUKIL8Wvi7dm4SqcSofR4xF5xBZre83MZXpHOr-Hg","expires_in":360,"token_type":"Bearer"}

在上一个脚本调解器中,您可以通过 mc.getPayloadJSON() 获取令牌访问令牌,这将给出与上面的 shwon 相同的响应