| | | 1 | | using Elsa.Identity.Contracts; |
| | | 2 | | using FastEndpoints; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Identity.Endpoints.Secrets.Hash; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Hash a given password. Requires the <code>SecurityRoot</code> policy. |
| | | 9 | | /// </summary> |
| | | 10 | | [PublicAPI] |
| | | 11 | | internal class Hash : Endpoint<Request, Response> |
| | | 12 | | { |
| | | 13 | | private readonly ISecretHasher _secretHasher; |
| | | 14 | | |
| | 1 | 15 | | public Hash(ISecretHasher secretHasher) |
| | | 16 | | { |
| | 1 | 17 | | _secretHasher = secretHasher; |
| | 1 | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <inheritdoc /> |
| | | 21 | | public override void Configure() |
| | | 22 | | { |
| | 1 | 23 | | Post("/identity/secrets/hash"); |
| | 1 | 24 | | Policies(IdentityPolicyNames.SecurityRoot); |
| | 1 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public override Task<Response> ExecuteAsync(Request request, CancellationToken cancellationToken) |
| | | 29 | | { |
| | 0 | 30 | | var hashedPassword = _secretHasher.HashSecret(request.Secret); |
| | 0 | 31 | | var response = new Response(hashedPassword.EncodeSecret(), hashedPassword.EncodeSalt()); |
| | | 32 | | |
| | 0 | 33 | | return Task.FromResult(response); |
| | | 34 | | } |
| | | 35 | | } |