对Microsoft.AspNetCore.Authentication认证组件的封装,简化使用
"AuthenticationOption": {
"Enabled": true,
"Secret": "6666666666666666", //最少配置16位
"Issuer": "NetPro.com",
"AccessTokenExpired": 6, //单位小时
"RefreshTokenExpired": 168 //单位小时
}
public void ConfigureServices(IServiceCollection services)
{
services.AddNetProAuthentication(configuration);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseNetProAuthentication();
}
[Authorize]
/// <summary>
/// 方法或者类加[Authorize]特性,此接口或者此控制器将启用JWT认证才可访问,具体参考示例
/// </summary>
public void Method()
[AllowAnonymous]
/// <summary>
/// 方法或者类加[Authorize]特性,此接口或者此控制器将强制匿名访问,具体参考示例
/// </summary>
public void Method()
如认证接口数量大于匿名接口数量,建议接口全局默认认证访问,可省去频繁[Authorize]
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers().RequireAuthorization();
});