mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: totp 2fa; httpcontext extension for jwtuser; asp.net data protection; prevent banned users from certain actions; account deletion requires 2fa if enabled; making users admins requires 2fa if enabled; httpcontext extension to get ip; enhance user store
refactor: organize dtos by domain; verification providers use verification context; move ip parsing into http context extensions chore: clean code
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using SharpbinV3.Server.DTOs;
|
||||
using SharpbinV3.Server.DTOs.Auth;
|
||||
using SharpbinV3.Server.Settings;
|
||||
using System.Text.Json;
|
||||
|
||||
@@ -13,26 +13,28 @@ namespace SharpbinV3.Server.Services.Verification.Providers
|
||||
public int Priority => 1;
|
||||
public bool IsConfigured => !string.IsNullOrEmpty(_authSettings.CF_Turnstile_SecretKey) && !string.IsNullOrEmpty(_authSettings.CF_Turnstile_SiteKey);
|
||||
|
||||
public async Task<bool> VerifyAsync(string token, string? ip)
|
||||
public async Task<bool> VerifyAsync(VerificationContext ctx)
|
||||
{
|
||||
if (_authSettings.CF_Turnstile_SecretKey is null)
|
||||
throw new InvalidOperationException("Turnstile secret key is not configured.");
|
||||
if (string.IsNullOrEmpty(ctx.Token))
|
||||
return false;
|
||||
|
||||
var parameters = new Dictionary<string, string>
|
||||
{
|
||||
{ "secret", _authSettings.CF_Turnstile_SecretKey },
|
||||
{ "response", token }
|
||||
{ "response", ctx.Token }
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(ip))
|
||||
parameters.Add("remoteip", ip);
|
||||
if (!string.IsNullOrEmpty(ctx.Ip))
|
||||
parameters.Add("remoteip", ctx.Ip);
|
||||
|
||||
var postContent = new FormUrlEncodedContent(parameters);
|
||||
|
||||
var response = await httpClient.PostAsync(SiteverifyUrl, postContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<TurnstileResponse>(json);
|
||||
var result = JsonSerializer.Deserialize<TurnstileResponseDto>(json);
|
||||
return result?.Success ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user