| | |
| | | using Furion.Authorization; |
| | | using Furion.DataEncryption; |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Http; |
| | | using System.Threading.Tasks; |
| | |
| | | |
| | | public class JwtHandler : AppAuthorizeHandler |
| | | { |
| | | public override async Task HandleAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext) |
| | | { |
| | | // 自动刷新 token |
| | | if (JWTEncryption.AutoRefreshToken(context, context.GetCurrentHttpContext())) |
| | | { |
| | | await AuthorizeHandleAsync(context); |
| | | } |
| | | else context.Fail(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 验证管道,也就是验证核心代码 |
| | | /// </summary> |
| | | /// <param name="context"></param> |
| | | /// <param name="httpContext"></param> |
| | | /// <returns></returns> |
| | | public override Task<bool> PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext) |
| | | { |
| | | // 这里写您的授权判断逻辑,授权通过返回 true,否则返回 false |
| | | |
| | | // 检查权限,如果方法是异步的就不用 Task.FromResult 包裹,直接使用 async/await 即可 |
| | | return Task.FromResult(true); |
| | | } |
| | | } |