ASP.NET core JWT authentication always throwing 401 unauthorized

前端 未结 4 507
借酒劲吻你
借酒劲吻你 2020-12-22 07:37

I\'m trying to implement JWT authentication on my asp.net core webAPI as simply as possible. I don\'t know what i\'m missing but it\'s always returning 401 even with the

4条回答
  •  温柔的废话
    2020-12-22 08:18

    Keep in mind that the UseAuthentication, UseRouting and UseAuthorization middleware must in correct in order for the ASP framework properly inject the identity context to http request.

    It should look like this: (.NET Core 3.1)

                app.UseAuthentication();
                app.UseRouting();
                app.UseAuthorization();
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllers();
                });
    

提交回复
热议问题