diff --git a/Yes.Application/Admins/Auths/ValidateCommandHandler.cs b/Yes.Application/Admins/Auths/ValidateCommandHandler.cs index 2bf6eb8..cb3976b 100644 --- a/Yes.Application/Admins/Auths/ValidateCommandHandler.cs +++ b/Yes.Application/Admins/Auths/ValidateCommandHandler.cs @@ -1,15 +1,15 @@  - namespace Yes.Application.Admins.Auths { public record ValidateCommand(string Token) : IRequest; public record ValidateCommandResponse(string Token, IdentityInfo Identity, int TokenLifetimeMinutes); - public class ValidateCommandHandler(BlogDbContext db, IOptionsMonitor options) : IRequestHandler + public class ValidateCommandHandler(BlogDbContext db, IOptionsMonitor options, IJwtProvider jwtProvider) : IRequestHandler { private readonly BlogDbContext _db = db; private readonly BlogSettings _settings = options.CurrentValue; + private readonly IJwtProvider _jwtProvider = jwtProvider; public async Task Handle(ValidateCommand request, CancellationToken cancellationToken) { var token = request.Token; @@ -20,21 +20,7 @@ namespace Yes.Application.Admins.Auths try { - var securityKeyBase64 = JwtHelper.GenerateKey(_settings.SecretKey ?? ""); - var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKeyBase64)); - - var jwtHander = new JwtSecurityTokenHandler(); - var claimsIdentity = jwtHander.ValidateToken(token, new TokenValidationParameters - { - ValidateIssuer = false, - ValidateAudience = false, - ValidateIssuerSigningKey = false, - ValidIssuer = "", - ValidAudience = "", - IssuerSigningKey = key, - ValidateLifetime = true, - - }, out _); + var claimsIdentity = await _jwtProvider.ReadToken(token); var id = int.Parse(claimsIdentity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value ?? "0"); diff --git a/Yes.Application/GlobalUsings.cs b/Yes.Application/GlobalUsings.cs index eebf572..1fb6b53 100644 --- a/Yes.Application/GlobalUsings.cs +++ b/Yes.Application/GlobalUsings.cs @@ -36,4 +36,5 @@ global using Yes.Infrastructure.Helpers; global using System.Security.Claims; global using System.IdentityModel.Tokens.Jwt; global using Microsoft.IdentityModel.Tokens; -global using System.Text; \ No newline at end of file +global using System.Text; +global using Yes.Infrastructure.Authorizations.Identity.Authroizations; \ No newline at end of file diff --git a/Yes.Blog/Endpoints/Admins/Configurations/GetConfigurationEndpoint.cs b/Yes.Blog/Endpoints/Admins/Configurations/GetConfigurationEndpoint.cs index 9cbf9a1..453290d 100644 --- a/Yes.Blog/Endpoints/Admins/Configurations/GetConfigurationEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Configurations/GetConfigurationEndpoint.cs @@ -2,7 +2,7 @@ { public class GetConfigurationEndpoint : ConfigurationEndpointScheme, IEndpoint { - public void Map(IEndpointRouteBuilder app) => app.MapGet("/configuration", Handle); + public void Map(IEndpointRouteBuilder app) => app.MapGet("/configuration", Handle).AllowAnonymous(); private async Task Handle(