Infrastructure.AccessToken.Authorization
1.1.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Infrastructure.AccessToken.Authorization --version 1.1.1
NuGet\Install-Package Infrastructure.AccessToken.Authorization -Version 1.1.1
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.1" />
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.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Infrastructure.AccessToken.Authorization, 1.1.1"
#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.1 // Install Infrastructure.AccessToken.Authorization as a Cake Tool #tool nuget:?package=Infrastructure.AccessToken.Authorization&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Infrastructure.AccessToken.Authorization
提供基于 JWT 的认证属性
- JWT签发地址: /getToken, 使用 agentId 和 secret 获取
- 基于Query的AccessToken的jwt验证
- 每个 Agent 可独立配置是否启用 IP 地址许可
使用说明
- Program.cs
//domain/handler接口依赖注入
builder.Services.AddSingleton<IJwtHelper, JwtHelper>();
app.UseMiddleware<AuthorizeMiddleware>();
- 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" ]
}
}
]
- appSettings.json 可配置是否启用 IP 日志跟踪(验证请求的来源IP 和配置的许可IP)
"JwtOption": {
"ExpireIn": 7200,
"ExpireInDeviation": 1,
"Secret": "",
"IPLogsOn": true //这里配置是否日志记录请求ip
}
- Api 使用 [Authorize]属性 标识JWT认证与IP许可
using Infrastructure.AccessToken.Authorization;
[Authorize]
[Route("api/[controller]/[action]")]
[ApiController]
public class YourController : ControllerBase
- Api 使用 [] 属性标识可匿名访问
using Infrastructure.AccessToken.Authorization;
[HttpGet]
[AllowAnonymous]
[Route("yourRoute")]
public async Task<IActionResult> YourService(CancellationToken ct = default)
Product | Versions 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.
-
net6.0
- Infrastructure.AccessToken.Domain (>= 1.1.0)
- Infrastructure.Crypto (>= 1.0.0)
- Infrastructure.UnifiedOutput (>= 1.1.4)
- Serilog.Sinks.File (>= 5.0.0)
- System.IdentityModel.Tokens.Jwt (>= 6.22.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.