天天看點

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 驗證