Add authentication methods to access protected resources #15

Merged
Wesser merged 13 commits from feat/auth into release/v1.0.0 2024-06-28 23:14:18 +03:00
2 changed files with 24 additions and 0 deletions
Showing only changes of commit a5f9e67647 - Show all commits

View File

@ -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);
}
}

View File

@ -95,6 +95,7 @@ public class Program
app.UseMiddleware<MaintenanceModeMiddleware>();
app.UseMiddleware<CustomExceptionHandlerMiddleware>();
app.UseMiddleware<JwtRevocationMiddleware>();
app.UseHttpsRedirection();