I have a .NET Core 2 (soon to be upgraded to 3) API with JWT. This API serves several specific companies under a parent company. The parent company generates the JWT, and they set the audience specific to the requesting company (multi-company APIs are a New Thing). Therefore, my API needs to support several different audiences.
Currently, we switch dynamically based on the request URL (the company ID is in the URL). This dynamic setting happens in OnMessageReceived:
OnMessageReceived = msgRcvdContext =>
{
companyId = GetCompanyId(msgRcvdContext.Request);
options.TokenValidationParameters.ValidAudience = GetAudienceByCompanyId(companyId);
}
Is this changing the "global" options, rather than the options for this particular request? If this isn't the right way to serve multiple audiences, how should I do it? Should I just put all the valid audiences into a list property in TokenValidationPrameters
? Or is there some other way I should do it?
Thank you.