Merge branch 'release' into 'master'

Release

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

View File

@@ -1,15 +1,15 @@

namespace Yes.Application.Admins.Auths
{
public record ValidateCommand(string Token) : IRequest<ValidateCommandResponse>;
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 BlogSettings _settings = options.CurrentValue;
private readonly IJwtProvider _jwtProvider = jwtProvider;
public async Task<ValidateCommandResponse> 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");

View File

@@ -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;
global using System.Text;
global using Yes.Infrastructure.Authorizations.Identity.Authroizations;

View File

@@ -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<IResult> Handle(