Store session cookies and proxy
Hi, Session cookie is not set in browser when I am using proxy
ng serve --proxy-config proxy.conf.json
proxy config:
{
"/api": {
"target": "https://test.org",
"secure": false
}
}
javascript:
const body = new window.URLSearchParams();
body.set('username', credentials.username);
body.set('password', credentials.password);
let loginHeaders = new Headers();
loginHeaders.append('Content-Type', 'application/x-www-form-urlencoded');
this.http
.post(`http://localhost:4200/api/auth`, body.toString(), {
headers: loginHeaders,
withCredentials: true
})
How can i set up proxy to store the session cookie in browser? What I am doing wrong?
OS?
Windows 10
Versions.
angular-cli: 1.0.0-beta.24 node: 6.9.1 os: win32 x64
I'm using option.cookiePathRewrite for rewriting the path headers . So, i added this option on my config proxy.Now, the cookie is stored and is sent to each request.
Angular CLI: 6.2.3
Node: 8.11.4
OS: darwin x64
Angular: 6.1.8
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.8.3
@angular-devkit/build-angular 0.8.3
@angular-devkit/build-optimizer 0.8.3
@angular-devkit/build-webpack 0.8.3
@angular-devkit/core 0.8.3
@angular-devkit/schematics 0.8.3
@angular/cli 6.2.3
@ngtools/webpack 6.2.3
@schematics/angular 0.8.3
@schematics/update 0.8.3
rxjs 6.3.2
typescript 2.9.1
webpack 4.19.1
I'm proxied to a test server that does not have SSL, so that is not my issue. I see two 307 redirects in Chrome dev tools Network tab. They both contain the cookie. But the final call to the API does not. 401 Unauthorized because the cookie isn't present.
@jkyoutsey I have been noticing something similar in my app as well after the most recent upgrade to Angular 6 (done last week). It definitely must be some configuration issue. In my specific case, it not working even for a production build (ng build --prod - which is then hosted separately/manually in the same web-server my server API resides in, hence no question of domain or SSL setting mismatch). Is your production build working fine?
@kichnan we refined our CORS configuration a bit to be more in line with the spec on MDN. But the reality was that the API we were calling just wasn't the right endpoint. I'm not sure our issue is resolved. But we've gotten past it. That API just was bad on the server side. All of my other calls are, in fact, passing the cookie just fine.
What's the answer Angular?
+1
+1
Hello, any update on this issue?
+1
Adding some random helper tips to troubleshoot this issue as I can remember them. Hope this helps.
- Make sure that the URL you are proxying is accessible.
- If you are using
ng serve --ssl true, make sure that the proxied server's SSL certificates are valid. For e.g., a self-signed locally generated certificate, though works in a browser, does not work for me in this situation, and especially over a network (LAN or internet). - If you are using
--ssl true, ensure that your proxy configurations have them set with"secure": true. Also try setting"changeOrigin": true. - If you are using
--ssl true, try keeping the server URL's "target" link as "https://" based even though auto-redirects (from http to https) may have been configured in the server.
I also had this problem, my final solution was this :
{
"/api": {
"target": "https://eventbroker-development.azurewebsites.net/api",
"secure": true,
"pathRewrite": {
"^/api": ""
},
"changeOrigin": true,
"logLevel": "debug",
"withCredentials": true,
"headers": {"Cookie":".AspNetCore.Cookies=CfDSSPKlUbmmqztPtpwdlsJqOPNIa3pjBw8MxFR4cc0z3cRVJgKDcCKxfxR-f8QEsUFzEh8Ch5iUiX0l_8XyleVjQRg2Cs1pq6dwhqBVcyqwsqcUdb8-l_ruFj6MqFEV3aYJqVnBlwTL-E9jRQALK6fRUv4PdWVyCTvDb3YNfSGntPjQx_sgA-5Q6b-L5Cps6TqxneQuE-zfzXocDO6H6496L3Ijyl5e5l6L5d2PgZNqpO5aHOHXvPxt5RkwXhinnk8Z6ynwAQoNc1obdRdfgvu8MwUWRvhkfgyAtiiy_2fwQP4kQ9429l-6f-o_5LV-N4MJUz4_am8Ci34EDOR6T1K0w2xoOeuvAH-eGhv6QoX30V9ZHWshMeYMtfMax7o2u0hI9vNetzSwGWlvhpbh1aS7wOyzaQmfpXwh7CeyEzdxhIbVO1cg1kLe5PTZpYZqBr-DIBcOOROXYJzr8mUKixvBiROnIl1qpKYt8_YP2Ra5kSurBJF9OhYB7qiMpQDe6nMYA7nlIiF_f72eDYfPVh3tnV0MuXUS6rV3raOj2qjd1C0RE69_DP61lMaMFgfbbLie4i7CvcddYEOJAJYnpSgWrA9lKsYilsHr2cDsMrOLfGXibi-9dU1n1oDvyZ3Mo3pAi5aMTiJhzf4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4S0SZSf2Ml9Rb_XfEjrmR5DnhEw0bby6ubbSrYxGNG6bqfLh93WOgReGLER2Z_OufPCxHTMtOa48pYRBpMtOlnX1z_Kj1v2bcfqAFeIZGvNFl-wgzGK3r29KmLCWnd32nvWQItRyzjSWrenLM9vLRoL49dKJL2U2bqmr7haGQKh9Jup-PofQoVsQdGPypBWEoyTGVW-tp0OmLvwGnshjx4Dwcu9MDrHghzIuC2-oE281Gnk8qeSeyEzg_rA0-1-xdWG_WI05e0i6xLMOQUFKlDoanvYi6oiSsO0JELfppK7s2N7BwcW-6yta5jfx9Zhc0y62m5RHi6c0I2PJubdBVYN0s1LXT27dMd55TuPMw57o_Rwb1D4i27lX8pk4EpE78MGa1ueXGL0VYeu-xoei3xOzoS4FuXEvp17oOncgDnXZMPdeecKOBoCIbDF1oLnwT6OGztMxfLIjlQMqEM84F85JZ6gGmDRWOxRdovwxa0aEqT7pNP_GSV0ycQzicZg8ZeO5a8-iplx4Rpna0AGiAa2aAygiV89OWYlPs9ijmWSpIO0BF3tDZmB78-EuHrF96cYg_hKCsZOVsq_aTIFUUsPLjcAVvfjJ0DKzdCCUCmKTCeQJdjR2Q-WH8AkAvV3NpdHhZ-yqVJf6dR1dfUBmVt9W5LAXrgAB"}
}
}
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.