mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
chore: format via csharpier
This commit is contained in:
@@ -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)
|
||||
@@ -36,9 +37,10 @@ namespace SharpbinV3.Server.Extensions
|
||||
.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 +49,7 @@ namespace SharpbinV3.Server.Extensions
|
||||
DisplayName = displayName,
|
||||
TotpEnabled = totpEnabled,
|
||||
Roles = roles.Length > 0 ? roles : [0],
|
||||
Expires = expires
|
||||
Expires = expires,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,7 +57,12 @@ namespace SharpbinV3.Server.Extensions
|
||||
{
|
||||
foreach (var header in ipHeaders)
|
||||
{
|
||||
if (context.Request.Headers.TryGetValue(header, out Microsoft.Extensions.Primitives.StringValues value))
|
||||
if (
|
||||
context.Request.Headers.TryGetValue(
|
||||
header,
|
||||
out Microsoft.Extensions.Primitives.StringValues value
|
||||
)
|
||||
)
|
||||
{
|
||||
var ip = value.FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(ip))
|
||||
|
||||
Reference in New Issue
Block a user