style: format via csharpier

This commit is contained in:
2026-02-10 17:15:29 -05:00
parent d2b9acb70f
commit 0d9a713247
33 changed files with 647 additions and 631 deletions
@@ -1,20 +1,21 @@
using SharpbinV3.Server.Services;
using System.IdentityModel.Tokens.Jwt;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using SharpbinV3.Server.Services;
namespace SharpbinV3.Server.Extensions
{
public static class HttpContextExtensions
{
public readonly static string[] ipHeaders =
public static readonly string[] ipHeaders =
[
"X-Forwarded-For",
"X-Real-IP",
"CF-Connecting-IP",
"True-Client-IP",
"X-Cluster-Client-IP",
"X-ProxyUser-IP"
"X-ProxyUser-IP",
];
public static JwtUser? GetJwtUser(this HttpContext context)
{
if (context.User == null || !context.User.Identity?.IsAuthenticated == true)
@@ -30,15 +31,13 @@ namespace SharpbinV3.Server.Extensions
var displayName = claims.FirstOrDefault(c => c.Type == "displayname")?.Value ?? "";
var totpEnabled = claims.FirstOrDefault(c => c.Type == "totp_enabled")?.Value == "True";
var roles = claims
.Where(c => c.Type == ClaimTypes.Role)
.Select(c => int.TryParse(c.Value, out var r) ? r : 0)
.ToArray();
var roles = claims.Where(c => c.Type == ClaimTypes.Role).Select(c => int.TryParse(c.Value, out var r) ? r : 0).ToArray();
var expClaim = claims.FirstOrDefault(c => c.Type == JwtRegisteredClaimNames.Exp)?.Value;
var expires = expClaim != null && long.TryParse(expClaim, out var expUnix)
? DateTimeOffset.FromUnixTimeSeconds(expUnix).UtcDateTime
: DateTime.UtcNow.AddMinutes(15);
var expires =
expClaim != null && long.TryParse(expClaim, out var expUnix)
? DateTimeOffset.FromUnixTimeSeconds(expUnix).UtcDateTime
: DateTime.UtcNow.AddMinutes(15);
return new JwtUser
{
@@ -47,7 +46,7 @@ namespace SharpbinV3.Server.Extensions
DisplayName = displayName,
TotpEnabled = totpEnabled,
Roles = roles.Length > 0 ? roles : [0],
Expires = expires
Expires = expires,
};
}