Seyounth.Auto.Hs/share/Syc.Authorize.JwtBearer/JwtBearerAuthenticationHandlerMiddleware.cs

28 lines
792 B
C#
Raw Normal View History

2025-06-04 09:42:48 +08:00
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Syc.Authorize.JwtBearer
{
public class JwtBearerAuthenticationHandlerMiddleware : IMiddleware
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
var user = context.User;
if (user == null || !user.Identities.Any(identity => identity.IsAuthenticated))
{
// 未认证,可以自定义处理逻辑
await context.Response.UnauthorizedAsync();
return;
}
// 继续处理请求
await next(context);
}
}
}