Added auth requirement on all endpoints. Added SignIn-, Access- and Refresh-Tokens based on JWT. Upgraded stored password to be based on PBKDF2. Added default password assignment. Updated logic to support auth-header and re-sign-in for tray-icon and web-ui.
37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using Duplicati.WebserverCore.Abstractions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Duplicati.WebserverCore.Endpoints.V1;
|
|
|
|
public class Captcha : IEndpointV1
|
|
{
|
|
public static void Map(RouteGroupBuilder group)
|
|
{
|
|
group.MapGet("/captcha/{token}", ([FromServices] ICaptchaProvider captchaProvider, [FromServices] IHttpContextAccessor httpContextAccessor, [FromRoute] string token, CancellationToken ct) =>
|
|
{
|
|
var jpeg = captchaProvider.GetCaptchaImage(token);
|
|
var response = httpContextAccessor.HttpContext!.Response;
|
|
response.ContentLength = jpeg.Length;
|
|
response.ContentType = "image/jpeg";
|
|
response.Body.WriteAsync(jpeg, ct);
|
|
});
|
|
|
|
group.MapPost("/captcha", ([FromServices] ICaptchaProvider captchaProvider, [FromBody] Dto.SolveCaptchaInputDto input) =>
|
|
{
|
|
var token = captchaProvider.CreateCaptcha(input.target);
|
|
return new { token };
|
|
})
|
|
.RequireAuthorization();
|
|
|
|
|
|
group.MapPost("/captcha/{token}", ([FromServices] ICaptchaProvider captchaProvider, [FromRoute] string token, [FromBody] Dto.SolveCaptchaInputDto input) =>
|
|
{
|
|
if (captchaProvider.SolvedCaptcha(token, input.target, input.answer ?? ""))
|
|
return new { success = true };
|
|
return new { success = false };
|
|
})
|
|
.RequireAuthorization();
|
|
|
|
}
|
|
}
|