AssignMessage policy for basic authentication

Dear Team,

I use "AssignMessage" policy to pass "Authorization basic: header to backend .

However, i am unable to dynamically convert to base64 format .

Is there any out-of-the-box way to convert to base64 format in apigee?


Or else which is the best javascript approach to convert to base64 format (please keep in mind this policy will be used heavily - 1 to 3 hits per 10 second )

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>SET AssignMessage</DisplayName>
    <Set>
        <Headers>
            <Header name="Authorization">Basic: xxxxxbase64formatxxxxxx </Header>
            <Header name="Content-Type">application/x-www-form-urlencoded</Header>
        </Headers>
        <QueryParams>
            <QueryParam name="grant_type">password</QueryParam>
        </QueryParams>
        <FormParams>
            <FormParam name="username" ref="request.queryparam.username"/>
            <FormParam name="password" ref="request.queryparam.password"/>
            <FormParam name="scope">openid</FormParam>
        </FormParams>
        <Verb>POST</Verb>
        <Path/>
    </Set>
    <AssignVariable>
        <Name>name</Name>
        <Value/>
        <Ref/>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Thanks & Best Regards

Sujith Mathew

1 5 1,395
5 REPLIES 5

Hi @Sujith Mathew

Yes, there is an out-of-the-box way to convert to base64 format in Edge.

It is possible to Base64 encode/decode values using JavaScript, however, I suggest you instead look into using the Basic Authentication policy. It will encode the value and attach it as an Authorization header to your request by simply requiring the username and password to be provided.

By the way, as per standard/specification RFC 7617, the example value in your example AssignMessage policy is invalid - Basic value, without the :

@Omid Tahouri

I cannot add basic authentication policy as you can see in my code above, i am using openid which requires to pass form parameters also.

Do you still think i can use basic authentication policy?

@Sujith Mathew - You do not need to modify your request in one single policy. You should be using multiple policies to perform different tasks -- think of each policy as invoking a method/function.

I suggest removing the <Header name="Authorization"> line from this AssignMessage policy and attaching a BasicAuthentication policy to the request in the target endpoint.

I will certainly try your suggestion and get back to you in max of 24 hours(my time zone is now end of day )

Not applicable

@Sujith Mathew

Just as Omid answered, you could keep using your current AssignMessage policy, but remove the Authorization header setup, and use Basic Authentication policy after that to setup the Basic Authorization header in your request.