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:
parent
79dffef528
commit
e007f15bce
8
DigitalData.Core.Security/GlobalSuppressions.cs
Normal file
8
DigitalData.Core.Security/GlobalSuppressions.cs
Normal 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)")]
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user