I have a function app which calls APIM and APIM have validate JWT token policy. I have assigned a managed Identity(system assigned). I want to generate access token so that I can utilize the jwt token validation. for that I tried to use the below code which is the sample given for key vault. what will be the equivalent for my case?
var tokenCredential = new DefaultAzureCredential();
var accessToken = await tokenCredential.GetTokenAsync(
new TokenRequestContext(scopes: new string[] { "https://vault.azure.net" + "/.default" }) { });
right now its able to fetch the token when I pass https://vault.azure.net. but I am generating the token for APIM what should I add here to get the token, so that I can validate audience in authentication policy in APIM.
var accessToken = await tokenCredential.GetTokenAsync(
new TokenRequestContext(scopes: new string[] { "--APIM?--" + "/.default" }) { });
My end goal is to Function app will generate access token and add it as part of the header to its rest api call to APIM. APIM will validate with validate_jwt policy.