commit change all folder

This commit is contained in:
Kham
2021-11-24 09:28:37 +11:00
parent 1131159112
commit 4e3cc0750c
58 changed files with 151 additions and 92 deletions
+36
View File
@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using System.Linq;
using System.Threading.Tasks;
using CarParkValidationAPI.Models;
using CarParkValidationAPI.Repository;
using CarParkValidationAPI.Interface;
namespace CarParkValidationAPI.Authorization
{
public class JwtMiddleware
{
private readonly RequestDelegate _next;
private readonly AppSettings _appSettings;
public JwtMiddleware(RequestDelegate next, IOptions<AppSettings> appSettings)
{
_next = next;
_appSettings = appSettings.Value;
}
public async Task Invoke(HttpContext context, IUserService userService, IJwtUtils jwtUtils)
{
var token = context.Request.Headers["Authorization"].FirstOrDefault()?.Split(" ").Last();
var user = jwtUtils.ValidateJwtToken(token);
if (user != null)
{
// attach user to context on successful jwt validation
//here to put in the real user
//TODO if you want to add information for User
context.Items["User"] = user;
}
await _next(context);
}
}
}