Get userinfo automatically in ASP.NET Core 3

Hello!

I’m trying to do something, which i feel should be quite simple, but i can’t seem to get it right.
I’m simply trying to build a web api in asp.net core where i can access the name (email, age, etc.) of the current user using the claims in the User object in a Controller.
I have followed the quickstart guide called “ASP.NET Core v3.0: Login” after creating an app of the “Regular web app” type.

However, whenever i make a call to my API I get an error message saying

Access to fetch at 'https://dev-nlzfjvrr.eu.auth0.com/authorize?client_id=cemBpHXcYnTC*************&x-client-ver=5.5.0.0' (redirected from 'https://localhost:5001/Invoice') from origin 'https://localhost:5001' has been blocked by CORS policy: 
Response to preflight request doesn`t pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. 
If an opaque response serves your needs, set the request`s mode to 'no-cors' to fetch the resource with CORS disabled.

I’ve added https://localhost:5001 to “Allowed Callback URLs” and “Allowed Web Origins”. I still doesn’t work.

Does anyone have any idea what might be causing this issue?

1 Like

Hi @SimplyZ,

CORS and localhost are mortal enemies :frowning:

Try using something like this CORS Everywhere extension https://addons.mozilla.org/en-US/firefox/addon/cors-everywhere/

Just set it to allow all origins, and give it a try. It’s worth noting that after you’re ready to deploy your app elsewhere, you do need to set CORS policy on the server, and make sure that you app is in fact following it (say, only allowing same origin requests). There’s a pretty neat article about setting it up in .NET Core: https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-3.1

Cheers!

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.