Access to XMLHttpRequest at '...' (redirected from 'https://localhost:44378/...') from origin 'http://localhost:3000' has been blocked by CORS policy

public class AccountController : Controller
{
    public IActionResult Login(string returnUrl)
    {
        return new ChallengeResult(
            GoogleDefaults.AuthenticationScheme,
            new AuthenticationProperties
            {
                RedirectUri = Url.Action(nameof(LoginCallback), new { returnUrl })
            });
    }
...

I have the controller shown above. If I type https://localhost:44378/Account/Login in the browser address bar it works fine - I get redirected to the Google authorization page but if I get redirected to this endpoint by hitting [Authorize] or a similar attribute on another endpoint I'm getting error like the following one:

Access to XMLHttpRequest at 'https://ift.tt/3u3Ma1Q' (redirected from 'https://localhost:44378/api/some-action') from origin 'http://localhost:3000' 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.

JIC, I added http://localhost:3000 to both Authorized JavaScript origins and Authorized redirect URIs in the app registration Google page.

Why so and how to solve it?



from Recent Questions - Stack Overflow https://ift.tt/3d5rWhm
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations