Modify Headers Add Policy Name


#1

Hi Martin,

I am using hybrid deployment. I would like to inject a header for a specific path in my API. So I’m trying to add an endpoint in my API with Modify Headers plugin for my path.

What I really want is to set the value of the header to the policy name used for the developer consuming the API.

For example, if we have 2 developers as follows:

  • Developer1 with an API key generated based on Policy1
  • Developer2 with an API key generated based on Policy2

I would like to inject a header lets say (AccessPolicy) with value Policy1 when I get a request from Developer1 and Policy2 when I get request from Developer2.

Is it possible to achieve this in tyk?

Thanks


#2

You would need to embed the policy type in the session metadata when you create the token for the user. Otherwise, no, the only data exposed is what’s in the session meta data field


#3

I saw in the cloud documentation for modifying headers an example for adding the uid of the user in the header by using $tyk_meta.uid.

Unfortunately I couldn’t find a place with documentation about the metadata that I can use to inject in headers.

Can you point me to such documentation?


#4

This is an example only, UID is not a real metadata field, you would need to add it yourself on key creation using the API

The session metadata is just a map of strings, it is arbitrary and completely up to you when you create the key.

The docs for the feature are here, you can manually add this data to a key using the key details page in the dashboard (scroll down to meta data section)