28 lines
792 B
C#
28 lines
792 B
C#
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);
|
|
}
|
|
}
|
|
}
|