How to support secure cookie in API management

Kewei Duan 1 Reputation point
2022-03-30T09:43:18.773+00:00

Recently, we decided to replace our customised code-based API gateway with the fully managed API management service from Azure. Our auth system is based on our own OIDC 2 service. I understand API management can support OIDC 2 integration as well as JWT validation. However, we previously save the auth token in cookie as well as some session info for API requests session between our API gateway and our React frontend. However, based on the docs I have seen so far, this cookie-based authentication is not supported and I do not see anything about maintaining sessions among multiple API calls.

So the question is, how to support secure cookie, cookie-based authentication or session in API management? Or do we have to rely on some alternative solutions, or API management does not suitable for our scenario? Thanks.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,448 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Mario Tiscareno 0 Reputation points
    2023-08-21T04:11:21.58+00:00

    This is more than a year old but I was looking for something like this so I'll share what I found hoping it saves people some time.

    Basically, Mike is right, but the key to making it work without friction is a handy attribute in the validate-jwt policy.

    You have three options to configure the source of the the token:

    • header-name
    • query-parameter
    • token-value (bingo)

    As explained in the documentation, you can define an "expression returning the token as a string". This basically allows you to get the token from anywhere in your context.

    Cookies can be a bit tricky to read, so you can do something like this to save it as a variable:

    https://stackoverflow.com/a/74036568/8835587

    As a bonus, if working with AD B2C you can use this policy instead, which also supports token-value:
    https://learn.microsoft.com/en-us/azure/api-management/validate-azure-ad-token-policy

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.