From 2d675a16adc0dc9fce8a85049eb9657d858848ee Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 20 Dec 2024 01:42:23 +0100 Subject: [PATCH] feat(TokenDescriptorProvider): Erstellt, um eine beliebige TokenDescription auf SecurityTokenDescriptor abzubilden. --- DigitalData.Core.Security/DIExtensions.cs | 4 +++- .../TokenDescriptorProvider.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 DigitalData.Core.Security/TokenDescriptorProvider.cs diff --git a/DigitalData.Core.Security/DIExtensions.cs b/DigitalData.Core.Security/DIExtensions.cs index b7816fb..2555719 100644 --- a/DigitalData.Core.Security/DIExtensions.cs +++ b/DigitalData.Core.Security/DIExtensions.cs @@ -22,7 +22,9 @@ namespace DigitalData.Core.Security return services; _mappingProfile.Added = true; - return services.AddAutoMapper(typeof(MappingProfile).Assembly); + return services + .AddAutoMapper(typeof(MappingProfile).Assembly) + .AddSingleton(); } } diff --git a/DigitalData.Core.Security/TokenDescriptorProvider.cs b/DigitalData.Core.Security/TokenDescriptorProvider.cs new file mode 100644 index 0000000..3b6c5f4 --- /dev/null +++ b/DigitalData.Core.Security/TokenDescriptorProvider.cs @@ -0,0 +1,19 @@ +using AutoMapper; +using DigitalData.Core.Security.Config; +using Microsoft.IdentityModel.Tokens; + +namespace DigitalData.Core.Security +{ + public class TokenDescriptorProvider + { + private readonly IMapper _mapper; + + public TokenDescriptorProvider(IMapper mapper) + { + _mapper = mapper; + } + + public SecurityTokenDescriptor Create(TokenDescription description) + => _mapper.Map(description, new SecurityTokenDescriptor()); + } +} \ No newline at end of file