Upgrading Scott Wildermuth's World Trip app to ASP.NET Core 2.0. The code below is not working.
Since I am using two authentication types and I would like both to work on the api controllers, I decided to use an Authorization policy.
public void ConfigureServices(IServiceCollection services) { //Some code here services.AddAuthentication() .AddCookie() .AddJwtBearer(/*Implementation is fine*/); services.AddAuthorization(options => { options.AddPolicy("Authenticated", policy => { policy.AddAuthenticationSchemes( CookieAuthenticationDefaults.AuthenticationScheme, JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser(); }); }); } Now in my controllers,
namespace TheWorld.Controllers.Api { [Route("api/trips")] [Authorize(policy: "Authenticated")] public class TripsController : controller { // Implementation is fine } } Requests coming from client (web) with cookie authentication is never seen as authenticated while requests from Jwt authenticated clients work as expected.
It only works with cookie authentication if I use the simple [Authorize] on the controller, in which asp.net core just chooses the default cookie authentication and never accepts requests from Jwt Clients.