Skip to content

LeonKou/NetPro.Authentication

Repository files navigation

Authentication使用

.NET Core NuGet

对Microsoft.AspNetCore.Authentication认证组件的封装,简化使用

使用

appsetting.json

"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();
      });

About

NetPro.Authentication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages