简体   繁体   English

如何将JWT用于asp.net Core

[英]How to use JWT for asp.net Core

I follow JWT Authentication for Asp.Net Web Api answer to add JWT to my asp.net core project but System.Web.Http.Filters is not supported in .net core?? 我遵循Asp.Net Web Api答案的JWT身份验证,将JWT添加到我的asp.net核心项目中,但.net核心不支持System.Web.Http.Filters

any better solution for securing web API ??? 任何用于保护Web API的更好的解决方案?

Filters are supported in ASP.NET Core MVC. ASP.NET Core MVC支持过滤器。 You can find them in Microsoft.AspNetCore.Mvc.Filters namespace. 您可以在Microsoft.AspNetCore.Mvc.Filters命名空间中找到它们。 Take a look at this guide for example. 本指南为例。

Bear in mind that you don't need to implement JWT authentication filter yourself. 请记住,您不需要自己实现JWT身份验证过滤器。 This has already been implemented as part of Microsoft.AspNetCore.Authentication.JwtBearer NuGet package. 这已作为Microsoft.AspNetCore.Authentication.JwtBearer NuGet包的一部分实现。 All you need is to use a JwtBearerAuthentication middleware in your app by adding app.UseJwtBearerAuthentication(new JwtBearerOptions { /* options */ }) to Startup.Configure() method. 您需要做的就是在应用程序中使用JwtBearerAuthentication中间件,方法是将app.UseJwtBearerAuthentication(new JwtBearerOptions { /* options */ })Startup.Configure()方法中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM