The error message "Token contains invalid audience" indicates that the aud claim in your JWT token does not match the expected audience for your Azure Event Grid namespace. To resolve this issue, ensure that the aud claim in your JWT is set correctly. It should be in the format of [namespace][region]-1.ts.eventgrid.azure.net/, where [namespace] is your Event Grid namespace and [region] is the Azure region where your namespace is hosted.
Additionally, verify that your Event Grid configuration is set up correctly for custom JWT authentication, including the issuer and the certificate settings. If the aud claim does not match the expected audience, the authentication will fail, resulting in the error you are seeing.
Make sure to check the following:
- The
audclaim in the JWT matches the expected format. - The issuer (
iss) in the JWT matches thetokenIssuerspecified in your Event Grid settings. - The JWT is not expired and is correctly signed with the issuer's certificate.
If these settings are correct and you are still facing issues, consider refreshing your JWT token and trying again.