如何将JWT用于asp.net Core [英] How to use JWT for asp.net Core

查看:115
本文介绍了如何将JWT用于asp.net Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循 Asp.Net Web Api的JWT身份验证回答将JWT添加到我的asp.net核心项目中,但.net核心不支持System.Web.Http.Filters?

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??

任何用于保护Web API的更好的解决方案?

any better solution for securing web API ???

推荐答案

ASP.NET Core MVC支持过滤器.您可以在Microsoft.AspNetCore.Mvc.Filters命名空间中找到它们.例如,参见本指南.

Filters are supported in ASP.NET Core MVC. You can find them in Microsoft.AspNetCore.Mvc.Filters namespace. Take a look at this guide for example.

请记住,您不需要自己实现JWT身份验证过滤器.这已作为Microsoft.AspNetCore.Authentication.JwtBearer NuGet软件包的一部分实现.您需要做的就是通过在Startup.Configure()方法中添加app.UseJwtBearerAuthentication(new JwtBearerOptions { /* options */ })来在应用程序中使用JwtBearerAuthentication中间件.

Bear in mind that you don't need to implement JWT authentication filter yourself. This has already been implemented as part of Microsoft.AspNetCore.Authentication.JwtBearer NuGet package. All you need is to use a JwtBearerAuthentication middleware in your app by adding app.UseJwtBearerAuthentication(new JwtBearerOptions { /* options */ }) to Startup.Configure() method.

这篇关于如何将JWT用于asp.net Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆