| | | 1 | | using Elsa.Identity.Constants; |
| | | 2 | | using Elsa.Identity.Contracts; |
| | | 3 | | using Elsa.Identity.Models; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Identity.Services; |
| | | 6 | | |
| | | 7 | | /// <inheritdoc /> |
| | | 8 | | public class DefaultClientIdGenerator : IClientIdGenerator |
| | | 9 | | { |
| | | 10 | | private readonly IRandomStringGenerator _randomStringGenerator; |
| | | 11 | | private readonly IApplicationProvider _applicationProvider; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Initializes a new instance of the <see cref="DefaultClientIdGenerator"/> class. |
| | | 15 | | /// </summary> |
| | 1 | 16 | | public DefaultClientIdGenerator(IRandomStringGenerator randomStringGenerator, IApplicationProvider applicationProvid |
| | | 17 | | { |
| | 1 | 18 | | _randomStringGenerator = randomStringGenerator; |
| | 1 | 19 | | _applicationProvider = applicationProvider; |
| | 1 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public async Task<string> GenerateAsync(CancellationToken cancellationToken = default) |
| | | 24 | | { |
| | 0 | 25 | | while (true) |
| | | 26 | | { |
| | 0 | 27 | | var clientId = _randomStringGenerator.Generate(16, CharacterSequences.AlphanumericSequence); |
| | 0 | 28 | | var filter = new ApplicationFilter { ClientId = clientId }; |
| | 0 | 29 | | var application = await _applicationProvider.FindAsync(filter, cancellationToken); |
| | | 30 | | |
| | 0 | 31 | | if (application == null) |
| | 0 | 32 | | return clientId; |
| | 0 | 33 | | } |
| | 0 | 34 | | } |
| | | 35 | | } |