Common.JwtToken 1.2.1

There is a newer prerelease version of this package available.
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.
<PackageVersion Include="Common.JwtToken" Version="1.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Common.JwtToken" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Common.JwtToken --version 1.2.1
                    
#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.
#:package Common.JwtToken@1.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Common.JwtToken&version=1.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Common.JwtToken&version=1.2.1
                    
Install as a Cake Tool

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 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.

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 192 1/21/2024 2.0.0-beta1 is deprecated because it is no longer maintained.
1.2.1 412 3/18/2023 1.2.1 is deprecated because it is no longer maintained.
1.2.0-beta2 260 2/6/2023
1.2.0-beta1 227 11/14/2022
1.1.3 603 4/27/2022
1.1.2 8,250 12/15/2020
1.1.1 555 11/27/2020
1.1.0 560 11/11/2020
1.0.0 553 10/10/2020