Missing CORS and Cookie Config Silently Broke Cross-Origin Auth in Angular-ASP.NET App
A developer building a School ERP system discovered that every API request from an Angular frontend to an ASP.NET Core backend returned 401 Unauthorized errors, despite both applications working correctly in isolation. No CORS error or exception was thrown; instead, the browser was silently discarding the authentication cookie on each cross-origin request. Investigation revealed three misconfigurations: the CORS policy lacked explicit credential allowance, the cookie defaulted to SameSite=Lax which blocks cross-origin cookies in modern browsers, and Angular was not configured to send credentials with requests. Fixing all three issues together — updating the CORS policy, setting SameSite=None with SecurePolicy=Always, and adding withCredentials: true in Angular — resolved the problem in roughly 10 lines of configuration. The developer noted that Postman masked the issue by being more permissive with cookies, making the browser's network tab the critical debugging tool.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in