WireMock.Net: Unauthorized (401) error when calling the admin API with version 2 Azure AAD tokens.
Describe the bug
- The application throws
401When it is configured to use version 2 of the AAD token. This happens because of the validation code here https://github.com/WireMock-Net/WireMock.Net/blob/e7310fbc7b2930be099e65b5673c7846576496f7/src/WireMock.Net/Authentication/AzureADAuthenticationMatcher.cs#L61
The issuwer from https://login.microsoftonline.com/{tennantID}/.well-known/openid-configuration is given as https://sts.windows.net/{tennantID}/ but when you decode a v2 AAD token using jwt.ms, the issuer is set as https://login.microsoftonline.com/{tennantID}/v2.0 And the recommendation is that instead of comparing the entire string, you should only compare that the tennants match. The identity model even has a helper method for validating the issuwer https://github.com/AzureAD/microsoft-identity-web/blob/36fb5f555638787823a89e89c67f17d6a10006ed/tools/CrossPlatformValidator/CrossPlatformValidation/CrossPlatformValidation/RequestValidator.cs#L42
Expected behavior:
I can make wiremock admin API requests with with AAD version 2 tokens
Test to reproduce
- Configure Wiremock server with AAD
- Generate an AAD token with version 2 https://learn.microsoft.com/en-us/entra/identity-platform/msal-acquire-cache-tokens
- Send a request to the server for the wiremock admin requests e.g
/__admin/requestsand you’ll get 401 instead of 200
Other related info
Provide additional information if any.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17
@StefH I downloaded the nupkg from here https://dev.azure.com/stef/WireMock.Net/_build/results?buildId=9960&view=artifacts&pathAsName=false&type=publishedArtifacts and ran the specific version.
I can confirm that the bug is now fixed I’m authenticating with 200
Hello @StefH
Thanks for the fast response, I’ll be able to test it out on Monday next week.