refactor(JwtSignatureService): removed primary constructor because this feature is not available in C# 11.0.

- Added GlobalSuppressions to avoid editor to offer this.
This commit is contained in:
Developer 02 2024-12-20 10:40:35 +01:00
parent 79dffef528
commit e007f15bce
2 changed files with 19 additions and 3 deletions

View File

@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Style", "IDE0290:Use primary constructor", Justification = "<Pending>", Scope = "member", Target = "~M:DigitalData.Core.Security.JwtSignatureService`1.#ctor(Microsoft.Extensions.Options.IOptions{DigitalData.Core.Security.Config.ClaimDescriptor{`0}},AutoMapper.IMapper)")]

View File

@ -6,13 +6,21 @@ using System.IdentityModel.Tokens.Jwt;
namespace DigitalData.Core.Security
{
public class JwtSignatureService<TPrincipal>(IOptions<ClaimDescriptor<TPrincipal>> claimDescriptorOptions, IMapper mapper) : JwtSecurityTokenHandler
public class JwtSignatureService<TPrincipal> : JwtSecurityTokenHandler
{
private readonly ClaimDescriptor<TPrincipal> _claimDescriptor = claimDescriptorOptions.Value;
private readonly ClaimDescriptor<TPrincipal> _claimDescriptor;
private readonly IMapper _mapper;
public JwtSignatureService(IOptions<ClaimDescriptor<TPrincipal>> claimDescriptorOptions, IMapper mapper)
{
_claimDescriptor = claimDescriptorOptions.Value;
_mapper = mapper;
}
public SecurityToken CreateToken(TPrincipal subject, TokenDescription description)
{
var descriptor = mapper.Map(description);
var descriptor = _mapper.Map(description);
descriptor.Claims = _claimDescriptor.CreateClaims?.Invoke(subject);
descriptor.Subject = _claimDescriptor.CreateSubject?.Invoke(subject);
return CreateToken(descriptor);