Darren Mitchinson
Darren Mitchinson

Reputation: 81

Angular 8 using Proxy.Conf.js shows username and password box

I have an angular 8 application and a separate .net core 3 API that has some methods that require windows authentication as they grab the users identity. The API is running on https://localhost:44328 and the angular app runs on http://localhost:4100. I have a proxy setup to get round the cors issues and have enable windows authentication and anonymous on the API.

The problem I keep getting is the angular app randomly pops up a username and password box after say the 3rd time it calls an API method with the [Authorize] attribute on the controller. I read somewhere this was a bug in an earlier version of build-webpack inside @angular-devkit but I'm now running on the latest version (0.803.15) and I'm still getting this issue. Does anyone know a fix for this or an alternative to using the proxy?

this is my proxy.cong.js file.

    const Agent = require('agentkeepalive').HttpsAgent;

module.exports = {
        '/api': {
        target: 'https://localhost:44328/',
            secure: false,            
            agent: new Agent({
                maxSockets: 100,
                keepAlive: true,
                maxFreeSockets: 10,
                keepAliveMsecs: 100000,
                timeout: 6000000,
                freeSocketTimeout: 90000
            }),
            changeOrigin:true,
        onProxyRes: proxyRes => {
            let key = 'www-authenticate';
            proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
        }
        }
};

UPDATE Back to the drawing board, the interceptor doesn't fix it, it just makes it happen a little bit less. I've tried profiling this in fiddler and I can constantly see the requests getting 401 error but then the next entry it shows the same message being sent again and then it authenticates. Eventually it will fail 3 times and its then when you get the username password box pop up.enter image description here

So from this you can see that 37,38 get the 401 error but eventually you get the success response 39. 55,56,57 all get the 401 error and this is when the browser shows the username password box.

Upvotes: 1

Views: 1112

Answers (1)

Darren Mitchinson
Darren Mitchinson

Reputation: 81

If anyone else comes across this problem then it's because I was also using an HTTP interceptor to set the withCredentials flag to true on the request. I think this is interfering with the proxy conf file so removing the interceptor when in development mode sorts the issue.

Upvotes: 2

Related Questions