How to extract http headers using a mediator

3.4k views Asked by At

How do I extract http headers like

Authorization: ​"admin 0PN5J17HBGZHT7JJ3X82"

where admin is the username and 0PN5J17HBGZHT7JJ3X82 is the password and assign it to a property/variable which would be then passed to a dss service for user login verification. From what I know our API can be do this using custom sequences and mediators (https://docs.wso2.com/display/AM170/Adding+Mediation+Extensions) but its not clear tome on how to extract this header and assign it to different property names like login and password.

Does a mediator header can take care of this? Or this there another way of doing by using a proxy service?

Header Mediator

<in>
    <header name="Authorization" value="admin 0PN5J17HBGZHT7JJ3X82" scope="transport"/>
    <send>
        <endpoint name="people">
            <address uri="http://localhost:9443/testapi/" format="get"/>
        </endpoint>
    </send>
</in>
<out>
    <send/>
</out>

Proxy Service

<proxy name="adminServiceProxy" transports="https http"
          startOnLoad="true" trace="disable">
      <description/>
      <target>
         <endpoint>
            <address uri="https://localhost:9443/testapi"/>
         </endpoint>
         <inSequence>
            <property name="Authorization"
                      expression="fn:concat('Basic ','admin:0PN5J17HBGZHT7JJ3X82')"
                      scope="transport"/>
         </inSequence>
         <outSequence>
          <send/>
         </outSequence>
      </target>
   </proxy>

Thank you

1

There are 1 answers

2
Ratha On BEST ANSWER

You can extract like this;

 <property name="AuthHeader" expression="$trp:Authorization"/>

Then log it and see what you are retrieving..

<log>
<property name =" Authheder value" expression=get-property('AuthHeader')/>
</log>

Then construct Basic auth header as you pointed in your proxy configuration. Here is a blog post which explains how you can retrive various information from a sequence