An Azure service that provides a hybrid, multi-cloud management platform for APIs.
Hello Warren Kinley, Thanks for reaching out on Microsoft Q&A and really appreciate your patience while we looked into this.
Currently, APIM policies do not support retrieving certificates by Key Vault Id. The context.Deployment.Certificates dictionary only allows access via the certificate thumbprint. So the approach you suggested (context.Deployment.Certificates["CertificateId"]) is not supported.
However, there are established workarounds to handle certificate rotation more gracefully:
- Use a Named Value for Thumbprint
- Create a named value in APIM, e.g., OracleCertThumbprint, containing the certificate thumbprint.
- Reference the named value in your policy:
<set-variable name="certificateThumbprint" value="{{OracleCertThumbprint}}" />
Pros: Keeps your policy code unchanged.string certificateId = context.Variables.GetValueOrDefault<string>("certificateThumbprint"); context.Deployment.Certificates.TryGetValue(certificateId, out var certificate);
Cons: You need to update the named value when the certificate rotates.
- Automate Thumbprint Update
- Set up an Azure Function, Logic App, or Azure Automation to:
- Detect Key Vault certificate rotation.
- Retrieve the new thumbprint.
- Update the APIM named value automatically.
- This makes your policy “rotation-proof.”
- Direct Key Vault Access in Policy (Advanced)
- You could use <send-request> to fetch the certificate from Key Vault at runtime.
- Requires APIM managed identity with Key Vault access.
- Adds latency and complexity, so generally not recommended.
Recommendation:
The best practice is to continue using thumbprints with a named value and automate its update upon Key Vault rotations. This avoids hardcoding thumbprints in your policy and keeps your JWT token generation resilient to certificate changes.
References:
Hope the above helps! Thank you.