1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using Microsoft.AspNetCore.Mvc.Filters;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Options;
- using System;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- namespace TEAMModelBI.Filter
- {
- public class ApiTokenAttribute : Attribute, IFilterFactory
- {
- public bool IsReusable => throw new NotImplementedException();
- /// <summary>
- /// 是否开启限流策略
- /// </summary>
- public bool Limit { get; set; }
- /// <summary>
- /// 授权序列
- /// </summary>
- public string Auth { get; set; }
- public IFilterMetadata CreateInstance(IServiceProvider services)
- {
- var option = services.GetService<IOptions<Option>>();
- var azureRedis = services.GetService<AzureRedisFactory>();
- return new InternalAuthTokenFilter(option, azureRedis, Auth, Limit);
- }
- private class InternalAuthTokenFilter : IResourceFilter
- {
- private readonly Option _option;
- //private readonly string _roles;
- private readonly string _auth;
- private readonly bool _limit;
- private readonly AzureRedisFactory _azureRedis;
- public InternalAuthTokenFilter(IOptions<Option> option, AzureRedisFactory azureRedis, string auth, bool limit)
- {
- _option = option.Value;
- _auth = auth;
- _limit = limit;
- _azureRedis = azureRedis;
- }
- public void OnResourceExecuting(ResourceExecutingContext context)
- {
- }
- public void OnResourceExecuted(ResourceExecutedContext context)
- {
- }
- }
- }
- }
|