| | | 1 | | using Elsa.Identity.Contracts; |
| | | 2 | | using Elsa.Identity.Entities; |
| | | 3 | | using Elsa.Identity.Models; |
| | | 4 | | using Elsa.Identity.Options; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Identity.Providers; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Represents a user provider that finds users using <see cref="UsersOptions"/>. |
| | | 12 | | /// </summary> |
| | | 13 | | [PublicAPI] |
| | | 14 | | public class ConfigurationBasedUserProvider : IUserProvider |
| | | 15 | | { |
| | | 16 | | private readonly IOptions<UsersOptions> _options; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="ConfigurationBasedUserProvider"/> class. |
| | | 20 | | /// </summary> |
| | 1 | 21 | | public ConfigurationBasedUserProvider(IOptions<UsersOptions> options) |
| | | 22 | | { |
| | 1 | 23 | | _options = options; |
| | 1 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public Task<User?> FindAsync(UserFilter filter, CancellationToken cancellationToken = default) |
| | | 28 | | { |
| | 0 | 29 | | var usersQueryable = _options.Value.Users.AsQueryable(); |
| | 0 | 30 | | var user = filter.Apply(usersQueryable).FirstOrDefault(); |
| | 0 | 31 | | return Task.FromResult(user); |
| | | 32 | | } |
| | | 33 | | } |