Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to change the basic Authorization header in the policies?

I am new to APIGEE and have the following use case -

  • request comes to APIGEE with basic Authorization header . The value is base64 encoded. Client also passes a custom auth header which is required by the backend.
  • after APIGEE verify the caller I need to change the basic Authorization header to a different value which client passes through custom auth header.
  • Then remove the custom auth header and call to backend 

 

please help me on this .

0 2 106
2 REPLIES 2

Hello,

I would recommend the use of the Assign Message Policy (noted here: https://cloud.google.com/apigee/docs/api-platform/reference/policies/assign-message-policy) to support your use case. By using the assign message policy, you would be able to remove/rewrite headers based on incoming key/value pairs (for your use case this would be the custom auth header information)

There are a ton of examples as per implementation within the document noted - if you have any specific questions/concerns please let us know!

A single AssignMessage policy to do the things OP mentioned (assign the value of one header to another, remove the custom auth header) would look like this: 

<AssignMessage name='AM-Reassign-Headers'>
  <Set>
    <Headers>
      <Header name='Authorization'>{request.header.CustomAuthHeader}</Header>
    </Headers>
  </Set>
  <Remove>
    <Headers>
      <Header name='CustomAuthHeader'/>
    </Headers>
  <Remove>
</AssignMessage>

I guess you will make sure to validate the Basic Auth header before over-writing it with this policy.