Merge branch 'develop' into 'release'

Develop

See merge request yescent/yes.blog!59
This commit is contained in:
2025-05-13 03:09:01 +00:00
3 changed files with 6 additions and 19 deletions

View File

@@ -1,15 +1,15 @@
 
namespace Yes.Application.Admins.Auths namespace Yes.Application.Admins.Auths
{ {
public record ValidateCommand(string Token) : IRequest<ValidateCommandResponse>; public record ValidateCommand(string Token) : IRequest<ValidateCommandResponse>;
public record ValidateCommandResponse(string Token, IdentityInfo Identity, int TokenLifetimeMinutes); public record ValidateCommandResponse(string Token, IdentityInfo Identity, int TokenLifetimeMinutes);
public class ValidateCommandHandler(BlogDbContext db, IOptionsMonitor<BlogSettings> options) : IRequestHandler<ValidateCommand, ValidateCommandResponse> public class ValidateCommandHandler(BlogDbContext db, IOptionsMonitor<BlogSettings> options, IJwtProvider jwtProvider) : IRequestHandler<ValidateCommand, ValidateCommandResponse>
{ {
private readonly BlogDbContext _db = db; private readonly BlogDbContext _db = db;
private readonly BlogSettings _settings = options.CurrentValue; private readonly BlogSettings _settings = options.CurrentValue;
private readonly IJwtProvider _jwtProvider = jwtProvider;
public async Task<ValidateCommandResponse> Handle(ValidateCommand request, CancellationToken cancellationToken) public async Task<ValidateCommandResponse> Handle(ValidateCommand request, CancellationToken cancellationToken)
{ {
var token = request.Token; var token = request.Token;
@@ -20,21 +20,7 @@ namespace Yes.Application.Admins.Auths
try try
{ {
var securityKeyBase64 = JwtHelper.GenerateKey(_settings.SecretKey ?? ""); var claimsIdentity = await _jwtProvider.ReadToken(token);
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 id = int.Parse(claimsIdentity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value ?? "0"); var id = int.Parse(claimsIdentity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value ?? "0");

View File

@@ -36,4 +36,5 @@ global using Yes.Infrastructure.Helpers;
global using System.Security.Claims; global using System.Security.Claims;
global using System.IdentityModel.Tokens.Jwt; global using System.IdentityModel.Tokens.Jwt;
global using Microsoft.IdentityModel.Tokens; global using Microsoft.IdentityModel.Tokens;
global using System.Text; global using System.Text;
global using Yes.Infrastructure.Authorizations.Identity.Authroizations;

View File

@@ -2,7 +2,7 @@
{ {
public class GetConfigurationEndpoint : ConfigurationEndpointScheme, IEndpoint 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<IResult> Handle( private async Task<IResult> Handle(