Jc.AuthorizationFilter.Jwt 2.2.15

There is a newer version of this package available.
See the version list below for details.
dotnet add package Jc.AuthorizationFilter.Jwt --version 2.2.15                
NuGet\Install-Package Jc.AuthorizationFilter.Jwt -Version 2.2.15                
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="Jc.AuthorizationFilter.Jwt" Version="2.2.15" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jc.AuthorizationFilter.Jwt --version 2.2.15                
#r "nuget: Jc.AuthorizationFilter.Jwt, 2.2.15"                
#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 Jc.AuthorizationFilter.Jwt as a Cake Addin
#addin nuget:?package=Jc.AuthorizationFilter.Jwt&version=2.2.15

// Install Jc.AuthorizationFilter.Jwt as a Cake Tool
#tool nuget:?package=Jc.AuthorizationFilter.Jwt&version=2.2.15                

Jc.AuthorizationFilter.Jwt

基于Jwt的token验证模块

使用方法

全局过滤 注入
//TokenHelper注入
builder.Services.AddScoped<TokenHelper>(opt=>new TokenHelper("192.168.1.83:6379,password=password123456"));

//Mvc过滤器注入
builder.Services.AddMvc(config=>
    {//TokenHelper注入
builder.Services.AddScoped<TokenHelper>(opt=>new TokenHelper("192.168.1.83:6379,password=password123456"));

//Mvc过滤器注入
builder.Services.AddMvc(config=>
    {
        config.Filters.Add( new Jc.AuthorizationFilter.Jwt(
            "Authorization",
            TokenFrom.Query));
    }
); 
        config.Filters.Add( new Jc.AuthorizationFilter.Jwt(
            "Authorization",
            TokenFrom.Query));
    }
); 

参数说明:
名称 必选 可空 说明
tokenName token的字段名
tokenFrom token的来源(Query|Hearder)
redisConn redis连接字符串

指定某个Controller或者Action不作用

增加以下属性
[AllowAnonymousAttribute]

将注入的实力 引用到控制器内

    private TokenHelper _tokenHelper;
 
    public WeatherForecastController(TokenHelper ctl)
    {
        _tokenHelper = ctl;
    }
创建Token
  res= _tokenHelper.Create(60,DateTime.Now.ToString(),new List<Claim>()
            {
                new Claim("name","jackerkun")
            });

tokenId:必须是唯一的 可以是用户的UUID等

手动获取token信息
    var res=_tokenHelper.GetTokenInfo(Request.Query["Authorization"].ToString());
在Action中 获取TokenInfo

注:一定要在Action入口处使用 否则 在其他过程使用 可能会错乱ID


//方法3 推荐
_tokenHelper.GetTokenInfo(tokenstring,fileldId)
    
//方法4 获取TokenString
Request.Headers["Authorization"].ToString();
Request.Query["Authorization"].ToString()

返回代码解释 重写 by yinlk 2024-06-13 改成 益体康特色的代码规范 还未整理文档

Code Msg Data explain
0 success TokenInfo Token信息
202 No identity information null 没有身份信息
203 Token verification failed: null token验证失败
204 Token time out null token超时
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
2.2.18 115 8/30/2024
2.2.17 167 8/21/2024
2.2.16 142 8/20/2024
2.2.15 137 8/19/2024
2.2.14 135 8/16/2024
2.2.13 125 8/16/2024
1.2.10 129 6/5/2024
1.2.9 903 10/19/2023
1.2.8 807 9/12/2023
1.2.7 882 9/5/2023
1.2.6 813 9/5/2023
1.2.5 762 9/5/2023
1.0.5 1,111 3/7/2023
1.0.4 1,406 3/25/2022
1.0.3 1,349 3/22/2022
1.0.2 1,368 3/21/2022
1.0.1 1,393 3/19/2022