Moves the six backend projects on disk into Core/ and Hosts/ subfolders, matching the solution folders already defined in Musify.slnx, so the file explorer reflects the same layout as the solution: backend/Core/Musify.Domain backend/Core/Musify.Application backend/Core/Musify.Infrastructure backend/Hosts/Musify.Api backend/Hosts/Musify.Worker backend/Hosts/Musify.StreamingGateway Updates every reference to the old paths: ProjectReference entries in Musify.Api.csproj and Musify.Worker.csproj, the three Dockerfiles, deploy/scripts/migrate.ps1|sh, deploy/zitadel/provision.ps1, deploy/up.ps1, deploy/README.md and docs/development.md. Also fixes a stale Dockerfile comment pointing at a compose file that no longer exists. Verified with `dotnet build Musify.slnx` against the new layout.
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using System.Security.Cryptography;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.IdentityModel.JsonWebTokens;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
using Musify.StreamingGateway.Configuration;
|
|
|
|
namespace Musify.StreamingGateway.Authentication;
|
|
|
|
public sealed class TicketValidator : IDisposable
|
|
{
|
|
private readonly StreamTicketValidationOptions _options;
|
|
private readonly RSA _rsa;
|
|
private readonly TokenValidationParameters _validationParameters;
|
|
private readonly JsonWebTokenHandler _handler = new();
|
|
|
|
public TicketValidator(IOptions<StreamTicketValidationOptions> options)
|
|
{
|
|
_options = options.Value;
|
|
|
|
_rsa = RSA.Create();
|
|
_rsa.ImportFromPem(File.ReadAllText(_options.PublicKeyPath));
|
|
|
|
_validationParameters = new TokenValidationParameters
|
|
{
|
|
ValidateIssuer = true,
|
|
ValidIssuer = _options.Issuer,
|
|
ValidateAudience = true,
|
|
ValidAudience = _options.Audience,
|
|
ValidateLifetime = true,
|
|
ValidateIssuerSigningKey = true,
|
|
IssuerSigningKey = new RsaSecurityKey(_rsa),
|
|
ValidAlgorithms = [SecurityAlgorithms.RsaSha256],
|
|
ClockSkew = TimeSpan.FromSeconds(30),
|
|
};
|
|
}
|
|
|
|
public async Task<string> ValidateTicketAsync(string? token)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(token))
|
|
return string.Empty;
|
|
|
|
var result = await _handler.ValidateTokenAsync(token, _validationParameters);
|
|
if (!result.IsValid)
|
|
return string.Empty;
|
|
|
|
var prefix = result.ClaimsIdentity?.FindFirst("prefix")?.Value;
|
|
return string.IsNullOrEmpty(prefix)? string.Empty : prefix;
|
|
}
|
|
|
|
public void Dispose() => _rsa.Dispose();
|
|
}
|