Infrastructure.AccessToken.Authorization 1.1.3

dotnet add package Infrastructure.AccessToken.Authorization --version 1.1.3                
NuGet\Install-Package Infrastructure.AccessToken.Authorization -Version 1.1.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Infrastructure.AccessToken.Authorization" Version="1.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Infrastructure.AccessToken.Authorization --version 1.1.3                
#r "nuget: Infrastructure.AccessToken.Authorization, 1.1.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Infrastructure.AccessToken.Authorization as a Cake Addin
#addin nuget:?package=Infrastructure.AccessToken.Authorization&version=1.1.3

// Install Infrastructure.AccessToken.Authorization as a Cake Tool
#tool nuget:?package=Infrastructure.AccessToken.Authorization&version=1.1.3                

Infrastructure.AccessToken.Authorization

提供基于 JWT 的认证属性

  1. JWT签发地址: /getToken, 使用 agentIdsecret 获取
  2. 基于Query的AccessToken的jwt验证
  3. 每个 Agent 可独立配置是否启用 IP 地址许可

使用说明

  1. Program.cs
    //domain/handler接口依赖注入
    builder.Services.AddSingleton<IJwtHelper, JwtHelper>();

    
    app.UseMiddleware<AuthorizeMiddleware>();
  1. appSettings.json
"Agents": [
    {
      "AgentId": "",
      "Secret": "",
      "AgentName": "",
      "WhiteIP": {
        "Enable": true, //启用 IP 许可
        "AllowIP": ["::1","127.0.0.1"]
      }
    },
    {
      "AgentId": "",
      "Secret": "",
      "AgentName": "",
      "WhiteIP": {
        "Enable": true,
        "AllowIP": [ "::1", "127.0.0.1" ]
      }
    }
  ]
  1. appSettings.json 可配置是否启用 IP 日志跟踪(验证请求的来源IP 和配置的许可IP)
  "JwtOption": {
    "ExpireIn": 7200,
    "ExpireInDeviation": 1,
    "Secret": "",
    "IPLogsOn": true //这里配置是否日志记录请求ip
  }
  1. Api 使用 [Authorize]属性 标识JWT认证与IP许可

using Infrastructure.AccessToken.Authorization;

[Authorize]
[Route("api/[controller]/[action]")]
[ApiController]
public class YourController : ControllerBase
  1. Api 使用 [] 属性标识可匿名访问
using Infrastructure.AccessToken.Authorization;

[HttpGet]
[AllowAnonymous]
[Route("yourRoute")]
public async Task<IActionResult> YourService(CancellationToken ct = default)

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 220 12/18/2023
1.1.2 185 11/8/2023
1.1.1 172 8/24/2023
1.1.0 198 7/11/2023
1.0.0 197 7/3/2023