Assign API key using assign message policy

Hi,

I am trying to append the query parms by adding the assign message policy. Below is the assign message policy which i am using. But it is not working. After assign message policy, i am using verify api key to validate which is failing with 401. can anyone please help me?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-2"> <DisplayName>Assign Message-2</DisplayName> <Properties/> <Set> <QueryParams> <QueryParm name="apikey">GNYSRySDw2WM63GcWoGDBihvmEAXDw02</QueryParm> </QueryParams> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>

0 5 477
5 REPLIES 5

@SRIDHAR ADURTHI

You do not need to hardcode the API Key in the policy. I assume you are passing the API Key as query param and want that to be validated using VerifyAPIKey. In that case, just update your VerifyAPIKey with the following code

<VerifyAPIKey name="APIKeyVerifier">
    <APIKey ref="request.queryparam.apikey" />
</VerifyAPIKey>

There are more examples in our docs. Check it out. You can remove the Assign Message policy and just have this policy.

Thanks @Sai Saran Vaidyanathan for the quick reply. Here is what I am doing. First i am using Verify API Key to validate the API key which I am passing from query parameters. Same policy which you mentioned, i have used. Then, I am using the assign message policy to remove the API key. Later again I am trying to use the assign message policy to add the API key and validate. There I am getting the 401. Below is the screen shot for my policy flow.

5951-untitled.png


Why do you want to do that ? VerifyAPIKey makes more sense for incoming traffic. Since you have already validated the incoming request, why do you want to do that again? I would not add the policies in the response flow

That makes sense. I am trying to learn more on assign message policy. So trying lot of options and one of the options is this. Is it not possible? Or my usage is wrong?

I appreciate you are trying different things to learn but this was not the right option to use. Please check out our docs for more info. Has a lot of useful info and samples. We have some samples here as well

Please continue to post any questions you have. This is a great place to collaborate, learn and share ideas