3

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

Community
  • 1
  • 1
Drew
  • 710
  • 1
  • 15
  • 34

1 Answers1

4

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

Ratha
  • 9,434
  • 17
  • 85
  • 163
  • You can define such mediation sequence and store in registry. And when publishing API , select the right sequence https://docs.wso2.com/display/AM170/Adding+Mediation+Extensions . Or else, yes you can define your complex sequences within a proxy service, and from APIManager call that proxy service as your endpoint. – Ratha Nov 19 '14 at 05:33
  • I have one more question once I have passed the headers and used them in the service is there a way to get the response and assign them to a header that can be used in the mediation sequence? – Drew Nov 21 '14 at 03:22