0

I have 2 api to request:

  1. API get token
  2. API request to work something (use OAuth2)

Below is code to call get token:

    <?xml version="1.0" encoding="UTF-8"?>
<api context="/default" name="PostToken" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence>
            <payloadFactory description="Setting payload for GetAccessToken API" media-type="xml">
                <format>
                    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                        <soapenv:Body>
                            <root xmlns="">
                                <grant_type>$1</grant_type>
                            </root>
                        </soapenv:Body>
                    </soapenv:Envelope>
                </format>
                <args>
                    <arg value="client_credentials"/>
                </args>
            </payloadFactory>
            <!-- Below configurations are required to send data as application/x-www-form-urlencoded -->
            <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"/>
            <header name="Authorization" scope="transport" value="Basic xxxxxxxx"/>
            <property name="POST_TO_URI" scope="axis2" type="STRING" value="true"/>
            <call>
                <endpoint>
                    <http method="post" uri-template="https://sample.com/token">
                        <suspendOnFailure>
                            <initialDuration>-1</initialDuration>
                            <progressionFactor>-1</progressionFactor>
                            <maximumDuration>0</maximumDuration>
                        </suspendOnFailure>
                        <markForSuspension>
                            <retriesBeforeSuspension>0</retriesBeforeSuspension>
                        </markForSuspension>
                    </http>
                </endpoint>
            </call>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

How next step I can get token from response to apply the 2nd API with Bearer token?

Many thanks!

1 Answers1

0

You can refer to the following blog regarding the Using OAuth2 Protected Back-ends With API Manager., This blog is regarding handling that in the WSO2 API Manager. But this is applicable in the EI as well.

[1] https://medium.com/@menakajayawardena/wso2-how-to-using-oauth2-protected-back-ends-with-api-manager-5d7e234c61c