DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

How to post application/x-www-form-urlencoded using dp:url in xslt to make a call to external OAUTH2 service?

  • 1.  How to post application/x-www-form-urlencoded using dp:url in xslt to make a call to external OAUTH2 service?

    Posted Sat January 23, 2021 04:22 PM

    My backend endpoint is https://targeturl.com/token.oauth2 and it accepts Content-type:application/x-www-form-urlencoded

    I should send below Key=Values in the POST Body. How i can i achieve in xslt dp:url call?

    grant_type:client_credentials

    client_id:7cjhfjsfb58378-48sfffs80--9bde31bc39c0

    client_secret:375dasdgs8ea282a-a5ssf2e-47aaf-sfsfa3f

    I wrote below code in xslt but i am getting 400 bad request. Please help me.

    <xsl:variable name="reqoauth">

    <xsl:text>client_id=7cjhfjsfb58378-48sfffs80--9bde31bc39c0</xsl:text> <xsl:text>&amp;client_secret=375dasdgs8ea282a-a5ssf2e-47aaf-sfsfa3f</xsl:text> <xsl:text>&amp;grant_type=client_credentials</xsl:text>

    </xsl:variable>

    <xsl:variable name="oAuthresponse">

    <dp:url-open target="{$OauthEndpoint}" response="responsecode-binary" content-type="application/x-www-form-urlencoded" ssl-proxy="client:OauthClientProfile" http-method="POST" data-type="base64" timeout="10">

    <xsl:value-of select="dp:encode(dp:encode($reqoauth,'url'),'base-64')"/>

    </dp:url-open>

    </xsl:variable>

    <xsl:variable name="tokenresp">

    <xsl:copy-of select="dp:stringToJSONx(dp:decode(dp:binary-encode($oAuthresponse/result/binary/node()),'base-64'))"/>

    </xsl:variable>

    When i checked the probe. The request and response are as below

    Request:

    client_id%3D7cjhfjsfb58378-48sfffs80--9bde31bc39c0%26client_secret%3D375dasdgs8ea282a-a5ssf2e-47aaf-sfsfa3f%26grant_type%3Dclient_credentials.

    Response:

    • <binary>***BINARY NODE***</binary>
    • <responsecode>400</responsecode>
    • <reasonphrase>Bad Request</reasonphrase>



    #DataPower
    #Support
    #SupportMigration


  • 2.  RE: How to post application/x-www-form-urlencoded using dp:url in xslt to make a call to external OAUTH2 service?

    Posted Mon January 25, 2021 08:49 AM

    Hi,

    are you absolutely sure that you need to base64 encode your POST payload? For example, Azure OAuth2.0 endpoint is called using application/x-www-form-urlencoded without any base64 encoding.

    --HP



    #DataPower
    #Support
    #SupportMigration