Configuring your backend to always require authentication  

It's much more secure to work in a whitelist approach where the default behavior of your application is to require all actions, and only allow anonymous access to APIs that explicitly allow it.

To set the implicit authentication requirement, we need to add an authentication filter to the request pipeline that is defined by the MVC infrastructure. This can be done by modifying the way we added MVC in the ConfigureServices method, as shown in the following code snippet:

// requires: using Microsoft.AspNetCore.Authorization;// using Microsoft.AspNetCore.Mvc.Authorization;services.AddMvc(config =>{    var policy = new AuthorizationPolicyBuilder()        .RequireAuthenticatedUser()        .Build(); config.Filters.Add(new ...

Get Hands-On Full-Stack Web Development with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.