diff --git a/Endpoint/Middleware/JwtRevocationMiddleware.cs b/Endpoint/Middleware/JwtRevocationMiddleware.cs new file mode 100644 index 0000000..97818c7 --- /dev/null +++ b/Endpoint/Middleware/JwtRevocationMiddleware.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Http; +using Mirea.Api.Security.Common.Interfaces; +using System.Threading.Tasks; + +namespace Mirea.Api.Endpoint.Middleware; + +public class JwtRevocationMiddleware(RequestDelegate next) +{ + public async Task Invoke(HttpContext context, IRevokedToken revokedTokenStore) + { + 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); + } +} \ No newline at end of file diff --git a/Endpoint/Program.cs b/Endpoint/Program.cs index cf016f4..a904e98 100644 --- a/Endpoint/Program.cs +++ b/Endpoint/Program.cs @@ -95,6 +95,7 @@ public class Program app.UseMiddleware(); app.UseMiddleware(); + app.UseMiddleware(); app.UseHttpsRedirection();