Sending Content-Type application/x-www-form-urlencoded WSO2 ESB

后端 未结 2 2024
时光说笑
时光说笑 2021-01-14 06:40

I have been working in a service chaining that answers me with a Bearer Token using in WSO2 EMM. I made a proxy in ESB and then I passed to a new sequence that makes the nex

相关标签:
2条回答
  • 2021-01-14 06:59

    I had the same error. This is my solution, similar to previous but in Json:

    <property name="scope" scope="default" type="STRING" value="myScope"/>
    <payloadFactory media-type="json">
        <format>{"grant_type":"password","username":"admin","password":"admin","scope":"$1"}</format>
        <args>
            <arg evaluator="xml" expression="get-property('scope')"/>
        </args>
    </payloadFactory>
    <!-- authorization header with consumer-key:consumer-secret in Base64 -->
    <header name="Authorization" scope="transport" value="Basic RUVyY0VRejFfU..."/>
    <header name="Content-Type" scope="transport" value="application/x-www-form-urlencoded"/>
    <property name="messageType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded"/>
    <call blocking="true">
        <endpoint key="GetToken"/>
    </call>
    
    0 讨论(0)
  • 2021-01-14 07:23

    I got it this is the answer

    <?xml version="1.0" encoding="UTF-8"?>
    <sequence name="Mensaje" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
        <property expression="json-eval($.client_secret)"
            name="client_secret" xmlns:ns="http://org.apache.synapse/xsd"/>
        <property expression="json-eval($.client_id)" name="client_id" xmlns:ns="http://org.apache.synapse/xsd"/>
        <property
            expression="fn:concat(get-property('client_id'),':',get-property('client_secret'))"
            name="Concatenados" xmlns:ns="http://org.apache.synapse/xsd"/>
        <property expression="base64Encode(get-property('Concatenados'))"
            name="Codificados" xmlns:ns="http://org.apache.synapse/xsd"/>
        <property
            expression="fn:concat('Basic ', get-property('Codificados'))"
            name="Autorizacion" xmlns:ns="http://org.apache.synapse/xsd"/>
        <property name="grant_type" value="password"/>
        <property name="username" value="admin"/>
        <property name="password" value="admin"/>
        <property name="scope" value="default"/>
        <payloadFactory media-type="xml">
            <format>
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                    <soapenv:Body>
                        <root xmlns="">
                            <grant_type>$1</grant_type>
                            <username>$2</username>
                            <password>$3</password>
                            <scope>$4</scope>
                        </root>
                    </soapenv:Body>
                </soapenv:Envelope>
            </format>
            <args>
                <arg evaluator="xml" expression="$ctx:grant_type" xmlns:ns="http://org.apache.synapse/xsd"/>
                <arg evaluator="xml" expression="$ctx:username" xmlns:ns="http://org.apache.synapse/xsd"/>
                <arg evaluator="xml" expression="$ctx:password" xmlns:ns="http://org.apache.synapse/xsd"/>
                <arg evaluator="xml" expression="$ctx:scope" xmlns:ns="http://org.apache.synapse/xsd"/>
            </args>
        </payloadFactory>
        <header name="Content-Type" scope="transport" value="application/x-www-form-urlencoded"/>
        <header expression="get-property('Autorizacion')"
            name="Authorization" scope="transport" xmlns:ns="http://org.apache.synapse/xsd"/>
        <property name="messageType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded"/>
        <property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
        <call>
            <endpoint name="Token">
                <http method="POST" uri-template="https://localhost:9443/oauth2/token"/>
            </endpoint>
        </call>
        <respond/>
    </sequence>
    
    0 讨论(0)
提交回复
热议问题