refactor: transfer logic
All logic related to token manipulation has been transferred to the AuthService. Also added TOTP 2FA and rethought the logic of logging into the application
This commit is contained in:
38
Security/Common/Domain/RequestContextInfo.cs
Normal file
38
Security/Common/Domain/RequestContextInfo.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Mirea.Api.Security.Services;
|
||||
using System;
|
||||
using System.Security;
|
||||
|
||||
namespace Mirea.Api.Security.Common.Domain;
|
||||
|
||||
internal class RequestContextInfo
|
||||
{
|
||||
public RequestContextInfo(HttpContext context, CookieOptionsParameters cookieOptions)
|
||||
{
|
||||
var ipEntity = context.Connection.RemoteIpAddress;
|
||||
|
||||
if (string.IsNullOrEmpty(ipEntity?.ToString()))
|
||||
throw new SecurityException("Ip is required for authorization.");
|
||||
|
||||
var ip = ipEntity.MapToIPv4().ToString();
|
||||
|
||||
var userAgent = context.Request.Headers.UserAgent.ToString();
|
||||
var fingerprint = context.Request.Cookies[CookieNames.FingerprintToken];
|
||||
|
||||
if (string.IsNullOrEmpty(fingerprint))
|
||||
{
|
||||
fingerprint = Guid.NewGuid().ToString().Replace("-", "") + GeneratorKey.GenerateString(32);
|
||||
cookieOptions.SetCookie(context, CookieNames.FingerprintToken, fingerprint);
|
||||
}
|
||||
|
||||
UserAgent = userAgent;
|
||||
Fingerprint = fingerprint;
|
||||
Ip = ip;
|
||||
RefreshToken = context.Request.Cookies["refresh_token"] ?? string.Empty;
|
||||
}
|
||||
|
||||
public string UserAgent { get; private set; }
|
||||
public string Ip { get; private set; }
|
||||
public string Fingerprint { get; private set; }
|
||||
public string RefreshToken { get; private set; }
|
||||
}
|
Reference in New Issue
Block a user