< Summary

Information
Class: Elsa.Identity.Endpoints.Secrets.Hash.Hash
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Endpoints/Secrets/Hash/Endpoint.cs
Line coverage
57%
Covered lines: 4
Uncovered lines: 3
Coverable lines: 7
Total lines: 42
Line coverage: 57.1%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
ExecuteAsync(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Endpoints/Secrets/Hash/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Authorization;
 3using Elsa.Identity.Contracts;
 4using JetBrains.Annotations;
 5
 6namespace Elsa.Identity.Endpoints.Secrets.Hash;
 7
 8/// <summary>
 9/// Hash a user password, returning the encoded hash and salt the user store would otherwise have written.
 10/// Requires <c>identity/users:create</c>. Scoped to user credentials only: application credentials are not
 11/// hashed here.
 12/// </summary>
 13/// <remarks>
 14/// This endpoint previously carried only the <c>SecurityRoot</c> policy, which by default resolved to nothing
 15/// more than "any authenticated caller" -- so any signed-in user could exercise the password hasher. It is
 16/// declared against identity/users:create because the credential it prepares is a user password: the caller
 17/// seeding a user out of band needs the same hash the user store would have written.
 18///
 19/// No application-provisioning flow reaches this endpoint, and none is documented to.
 20/// <c>POST /identity/applications</c> generates the client secret and the API key itself, hashes both, and
 21/// returns each plaintext alongside its hash, so <c>identity/applications:create</c> on its own stays
 22/// sufficient to create an application end to end. See ADR 0010.
 23/// </remarks>
 24[PublicAPI]
 325internal class Hash(ISecretHasher secretHasher) : ElsaEndpoint<Request, Response>
 26{
 27    /// <inheritdoc />
 28    public override void Configure()
 29    {
 530        Post("/identity/secrets/hash");
 531        RequirePermission(Elsa.Identity.Permissions.IdentityPermissions.Users, CoreVerbs.Create);
 532    }
 33
 34    /// <inheritdoc />
 35    public override Task<Response> ExecuteAsync(Request request, CancellationToken cancellationToken)
 36    {
 037        var hashedPassword = secretHasher.HashSecret(request.Secret);
 038        var response = new Response(hashedPassword.EncodeSecret(), hashedPassword.EncodeSalt());
 39
 040        return Task.FromResult(response);
 41    }
 42}