| | | 1 | | using Elsa.ExternalAuthentication.Contracts; |
| | | 2 | | using Elsa.ExternalAuthentication.Models; |
| | | 3 | | using Elsa.ExternalAuthentication.Options; |
| | | 4 | | using Microsoft.Extensions.Options; |
| | | 5 | | |
| | | 6 | | namespace Elsa.ExternalAuthentication.Services; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Provides the startup-installed adapter catalog without coupling callers to a concrete adapter. |
| | | 10 | | /// </summary> |
| | | 11 | | public sealed class DefaultExternalAuthenticationAdapterRegistry : IExternalAuthenticationAdapterRegistry |
| | | 12 | | { |
| | | 13 | | private readonly IReadOnlyDictionary<string, IExternalAuthenticationAdapter> _adapters; |
| | | 14 | | private readonly IReadOnlyCollection<ExternalAuthenticationAdapterDescriptor> _descriptors; |
| | | 15 | | |
| | 5 | 16 | | public DefaultExternalAuthenticationAdapterRegistry( |
| | 5 | 17 | | IEnumerable<IExternalAuthenticationAdapter> adapters, |
| | 5 | 18 | | ExtensionDescriptorValidator descriptorValidator, |
| | 5 | 19 | | IOptions<ExternalAuthenticationOptions> options) |
| | | 20 | | { |
| | 5 | 21 | | _adapters = ExtensionRegistryBuilder.Create( |
| | 5 | 22 | | adapters, |
| | 6 | 23 | | adapter => adapter.Type, |
| | 5 | 24 | | options.Value.AllowedAdapterTypes, |
| | 5 | 25 | | "adapter"); |
| | 4 | 26 | | _descriptors = _adapters.Values |
| | 4 | 27 | | .Select(descriptorValidator.Validate) |
| | 0 | 28 | | .OrderBy(x => x.Type, StringComparer.Ordinal) |
| | 4 | 29 | | .ToArray(); |
| | 4 | 30 | | } |
| | | 31 | | |
| | 1 | 32 | | public IReadOnlyCollection<ExternalAuthenticationAdapterDescriptor> ListDescriptors() => _descriptors; |
| | | 33 | | |
| | 7 | 34 | | public bool TryGet(string type, out IExternalAuthenticationAdapter adapter) => _adapters.TryGetValue(type, out adapt |
| | | 35 | | } |