<p>Context:-<br />
I am following <a href="https://kubernetes.github.io/ingress-nginx/examples/auth/external-auth/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/auth/external-auth/</a> to enable authentication for my application by using ingress.</p>
<p>Issue:-<br />
Instead of using <a href="https://httpbin.org/basic-auth/user/passwd" rel="nofollow noreferrer">https://httpbin.org/basic-auth/user/passwd</a> as auth url, I am using the FQDN of my service running in same namespace.<br />
So my annotations looks like:</p>
<pre><code>annotations:
    nginx.ingress.kubernetes.io/auth-url: http://myservice.mynamespace.svc.cluster.local:9995/auth/
</code></pre>
<p>where 9995 is the port where myservice exposes /auth/ endpoint<br />
This  works when I use curl to hit my APIs passing in the credentials using -u flag.<br />
<code>curl -XGET &quot;http://minikubeip/myapp/status/&quot; -H &quot;Content-Type: application/json&quot; -u &quot;$USERNAME:$PASSWORD&quot;</code><br />
response:-<br />
<code>{&quot;status&quot;:&quot;working&quot;}</code></p>
<p>But when I open http://minikubeip/myapp/status/ in my browser it immediately returns me 401 page without showing the authentication popup.<br />
When I use <a href="https://httpbin.org/basic-auth/user/passwd" rel="nofollow noreferrer">https://httpbin.org/basic-auth/user/passwd</a> for nginx.ingress.kubernetes.io/auth-url both curl and browser work, with browser showing me a pop-up to enter password.</p>
<p>I checked httpbin.org and see that it is a <a href="http://httpbin.org/#/Auth/get_basic_auth__user___passwd_" rel="nofollow noreferrer">GET endpoint</a> which returns 200 for success and 401 for failure. My /auth API is exactly the same specification</p>
<p>My question is: Do I need to do something special for browser to show the basic-auth popup dialog?</p>

abnvanand
<p>I had to add</p>
<p>w.Header().Set(&quot;WWW-Authenticate&quot;, <code>Basic realm=&quot;mydomain&quot;</code>)</p>
<p>Found it here: <a href="https://stackoverflow.com/a/36188200">https://stackoverflow.com/a/36188200</a></p>
