I am trying to setup availability testing (URL Ping Test) with Azure Application Insights on an endpoint that requires basic authentication. It seems that the standard approach with
https://username:password@myendpoint.com
isn't accepted by Azure (error message says that the URL is malformed and maybe I am missing https/http at the beginning).
Is there any other way to achieve this except of using multi-step web test or Azure Functions, assuming I want to stay in Azure ecosystem? :)
Passing the basic auth credentials in the URL has been deprecated by RFC 3986 (Here is a snippet from the RFC)
3.2.1. User Information
The userinfo subcomponent may consist of a user name and, optionally, scheme-specific information about how to gain authorization to access the resource. The user information, if present, is followed by a commercial at-sign ("@") that delimits it from the host.
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
Use of the format "user:password" in the userinfo field is deprecated.
The alternate would be to use the Authorization header to pass the credentials. Here is a snippet from Wikipedia (Basic Auth) on how this header is constructed.
The Authorization field is constructed as follows:[6]
- The username and password are combined with a single colon. (:)
- The resulting string is encoded into an octet sequence.[7]
- The resulting string is encoded using a variant of Base64.[8]
- The authorization method and a space is then prepended to the encoded string, separated with a space (e.g. "Basic ").
For example, if the browser uses Aladdin as the username and OpenSesame as the password, then the field's value is the base64-encoding of Aladdin:OpenSesame, or
QWxhZGRpbjpPcGVuU2VzYW1l
. Then the Authorization header will appear as:Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l
You can create a Web Test file in Visual Studio Enterprise and then upload it in Application insights and use that. Refer this doc: https://learn.microsoft.com/en-us/azure/application-insights/app-insights-monitor-web-app-availability
<Request> <Headers> <Header Name="Authorization" Value="Basic QWxhZGRpbjpPcGVuU2VzYW1l" /> </Headers> </Request>