|
@@ -41,38 +41,38 @@ namespace TEAMModelOS.Filter
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 是否免费调用
|
|
/// 是否免费调用
|
|
/// </summary>
|
|
/// </summary>
|
|
- public bool free { get; set; }
|
|
|
|
|
|
+ ///public bool free { get; set; }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 每次调用花费多少钱
|
|
/// 每次调用花费多少钱
|
|
/// </summary>
|
|
/// </summary>
|
|
- public decimal cost { get; set; }
|
|
|
|
|
|
+ ///public decimal cost { get; set; }
|
|
}
|
|
}
|
|
|
|
|
|
public class ApiTokenAttribute : Attribute, IFilterFactory
|
|
public class ApiTokenAttribute : Attribute, IFilterFactory
|
|
{
|
|
{
|
|
public bool IsReusable => true;
|
|
public bool IsReusable => true;
|
|
public bool Limit { get; set; }
|
|
public bool Limit { get; set; }
|
|
- public string Permission { get; set; }
|
|
|
|
|
|
+ public string Auth { get; set; }
|
|
|
|
|
|
public IFilterMetadata CreateInstance(IServiceProvider services)
|
|
public IFilterMetadata CreateInstance(IServiceProvider services)
|
|
{
|
|
{
|
|
var option = services.GetService<IOptions<Option>>();
|
|
var option = services.GetService<IOptions<Option>>();
|
|
var azureRedis = services.GetService<AzureRedisFactory>();
|
|
var azureRedis = services.GetService<AzureRedisFactory>();
|
|
- return new InternalAuthTokenFilter(option ,azureRedis, Permission, Limit);
|
|
|
|
|
|
+ return new InternalAuthTokenFilter(option ,azureRedis, Auth, Limit);
|
|
}
|
|
}
|
|
|
|
|
|
private class InternalAuthTokenFilter : IResourceFilter
|
|
private class InternalAuthTokenFilter : IResourceFilter
|
|
{
|
|
{
|
|
private readonly Option _option;
|
|
private readonly Option _option;
|
|
//private readonly string _roles;
|
|
//private readonly string _roles;
|
|
- private readonly string _permission;
|
|
|
|
|
|
+ private readonly string _auth;
|
|
private readonly bool _limit;
|
|
private readonly bool _limit;
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
|
|
|
|
- public InternalAuthTokenFilter(IOptions<Option> option, AzureRedisFactory azureRedis, string permission,bool limit)
|
|
|
|
|
|
+ public InternalAuthTokenFilter(IOptions<Option> option, AzureRedisFactory azureRedis, string auth, bool limit)
|
|
{
|
|
{
|
|
_option = option.Value;
|
|
_option = option.Value;
|
|
- _permission = permission;
|
|
|
|
|
|
+ _auth = auth;
|
|
_limit = limit;
|
|
_limit = limit;
|
|
_azureRedis = azureRedis;
|
|
_azureRedis = azureRedis;
|
|
}
|
|
}
|
|
@@ -88,11 +88,11 @@ namespace TEAMModelOS.Filter
|
|
id = jwt.Payload.Sub;
|
|
id = jwt.Payload.Sub;
|
|
school = jwt.Payload.Azp;
|
|
school = jwt.Payload.Azp;
|
|
jti = jwt.Payload.Jti;
|
|
jti = jwt.Payload.Jti;
|
|
- var permissions = jwt.Claims.Where(c => c.Type == "permissions");
|
|
|
|
|
|
+ var permissions = jwt.Claims.Where(c => c.Type.Equals("auth"));
|
|
///当前请求的api的设置的permission值是否包含在 从jwt的获取["1","2","3","4","5"]值中
|
|
///当前请求的api的设置的permission值是否包含在 从jwt的获取["1","2","3","4","5"]值中
|
|
- if (!string.IsNullOrWhiteSpace(_permission)&& permissions.Count()>0)
|
|
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(_auth)&& permissions.Count()>0)
|
|
{
|
|
{
|
|
- if (permissions.Select(x=>x.Value).Contains(_permission))
|
|
|
|
|
|
+ if (permissions.Select(x=>x.Value).Contains(_auth))
|
|
{
|
|
{
|
|
pass = true;
|
|
pass = true;
|
|
}
|
|
}
|
|
@@ -104,7 +104,7 @@ namespace TEAMModelOS.Filter
|
|
if (_limit)
|
|
if (_limit)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (pass)
|
|
if (pass)
|