Common.JwtToken
1.2.1
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
Suggested Alternatives
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Common.JwtToken --version 1.2.1
NuGet\Install-Package Common.JwtToken -Version 1.2.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="Common.JwtToken" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Common.JwtToken --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Common.JwtToken, 1.2.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 Common.JwtToken as a Cake Addin #addin nuget:?package=Common.JwtToken&version=1.2.1 // Install Common.JwtToken as a Cake Tool #tool nuget:?package=Common.JwtToken&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
jwtToken包
一个封装了jwt使用以及swagger启用等的包
快速上手
认证
注入jwt服务
services.AddJwtTokenService(options =>
{
options.JwtAudience = "aaaa";
options.JwtIssuer = "bbbb";
});
开启认证
app.UseAuthentication();
app.UseAuthorization();
使用服务IJwtAuthService
private readonly IJwtAuthService _jwtAuthService;
private readonly ILogger<TokenController> _logger;
public TokenController(IJwtAuthService jwtAuthService, ILogger<TokenController> logger)
{
_jwtAuthService = jwtAuthService;
_logger = logger;
}
/// <summary>
/// 获取token
/// </summary>
/// <returns></returns>
[HttpGet]
public string GetToken()
{
var claim = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier,"111111"),
new Claim(ClaimTypes.Role,"123456")
};
return _jwtAuthService.CreateToken(claim);
}
授权
注入服务
services.AddCustomerAuthorization("default");
实现授权获取接口,例如
public class PermissionService : IPermissionService
{
public Task<List<RolePermissionRelationDto>> GetRoleAuthAsync()
{
return Task.FromResult(new List<RolePermissionRelationDto>()
{
new RolePermissionRelationDto("123456","/api/token/get")
});
}
}
注入
services.AddScoped<IPermissionService, PermissionService>();
在需要开启授权的Action上标注
[Authorize("default")]
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. 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 is compatible. 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. |
.NET Core | netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- AzrngCommon.Core (>= 1.0.1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 3.1.9)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.4.0)
- Swashbuckle.AspNetCore.SwaggerUI (>= 6.4.0)
-
net5.0
- AzrngCommon.Core (>= 1.0.1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 5.0.0)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.4.0)
- Swashbuckle.AspNetCore.SwaggerUI (>= 6.4.0)
-
net6.0
- AzrngCommon.Core (>= 1.0.1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 6.0.0)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.4.0)
- Swashbuckle.AspNetCore.SwaggerUI (>= 6.4.0)
-
net7.0
- AzrngCommon.Core (>= 1.0.1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 7.0.0)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.4.0)
- Swashbuckle.AspNetCore.SwaggerUI (>= 6.4.0)
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 | |
---|---|---|---|
2.0.0-beta1 | 159 | 1/21/2024 | |
1.2.1 | 333 | 3/18/2023 | |
1.2.0-beta2 | 198 | 2/6/2023 | |
1.2.0-beta1 | 169 | 11/14/2022 | |
1.1.3 | 525 | 4/27/2022 | |
1.1.2 | 8,085 | 12/15/2020 | |
1.1.1 | 456 | 11/27/2020 | |
1.1.0 | 460 | 11/11/2020 | |
1.0.0 | 454 | 10/10/2020 |