2024-06-15 21:53:00 +03:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Mirea.Api.Security.Common.Interfaces;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Mirea.Api.Endpoint.Middleware;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|