2024-06-15 21:53:00 +03:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Mirea.Api.Security.Common.Interfaces;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-10-07 02:25:36 +03:00
|
|
|
|
namespace Mirea.Api.Endpoint.Configuration.Core.Middleware;
|
2024-06-15 21:53:00 +03:00
|
|
|
|
|
|
|
|
|
public class JwtRevocationMiddleware(RequestDelegate next)
|
|
|
|
|
{
|
2024-08-12 21:36:07 +03:00
|
|
|
|
public async Task InvokeAsync(HttpContext context, IRevokedToken revokedTokenStore)
|
2024-06-15 21:53:00 +03:00
|
|
|
|
{
|
|
|
|
|
if (context.Request.Headers.ContainsKey("Authorization"))
|
|
|
|
|
{
|
|
|
|
|
var token = context.Request.Headers.Authorization.ToString().Replace("Bearer ", "");
|
|
|
|
|
if (await revokedTokenStore.IsTokenRevokedAsync(token))
|
|
|
|
|
{
|
|
|
|
|
context.Response.StatusCode = StatusCodes.Status401Unauthorized;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await next(context);
|
|
|
|
|
}
|
|
|
|
|
}
|