23 lines
		
	
	
		
			748 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			748 B
		
	
	
	
		
			C#
		
	
	
	
	
	
using Microsoft.AspNetCore.Http;
 | 
						|
using Mirea.Api.Security.Common.Interfaces;
 | 
						|
using System.Threading.Tasks;
 | 
						|
 | 
						|
namespace Mirea.Api.Endpoint.Configuration.Core.Middleware;
 | 
						|
 | 
						|
public class JwtRevocationMiddleware(RequestDelegate next)
 | 
						|
{
 | 
						|
    public async Task InvokeAsync(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);
 | 
						|
    }
 | 
						|
} |