天天看点

Asp.net core web Api 应用Jwt 验证

1、新建Asp.net core web Api 应用程序

Asp.net core web Api 应用Jwt 验证

2、目录结构

Asp.net core web Api 应用Jwt 验证

3、Nuget包下载安装

Microsoft.AspNetCore.Authentication.JwtBearer

Newtonsoft.Json

4、修改launchSettings.json

5、WeatherForecastController

6、修改appsettings.json

7、添加JwtTokenField.cs

8、添加RequestUser.cs

9、添加IAuthorizeService.cs

10、添加AuthorizeService.cs

11、修改Startup.cs

12、添加AuthenticationController.cs

备注:[AllowAnonymous]特性添加后,Action不会被验证

13、启动运行

Asp.net core web Api 应用Jwt 验证

14、使用Postman访问APi资源

Asp.net core web Api 应用Jwt 验证