mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
[PM-15015] Add Country Name to auth request from request headers (#5471)
* feat(pm-15015) : * Add `CountryName` column to AuthRequest Table in Database, and refreshing AuthRequestView * Modify database stored procedures and Entity Framework migrations for AuthRequest Repositories * Add property to `ICurrentContext` and response models.
This commit is contained in:
@ -16,6 +16,12 @@ public class AuthRequest : ITableObject<Guid>
|
||||
public DeviceType RequestDeviceType { get; set; }
|
||||
[MaxLength(50)]
|
||||
public string RequestIpAddress { get; set; }
|
||||
/// <summary>
|
||||
/// This country name is populated through a header value fetched from the ISO-3166 country code.
|
||||
/// It will always be the English short form of the country name. The length should never be over 200 characters.
|
||||
/// </summary>
|
||||
[MaxLength(200)]
|
||||
public string RequestCountryName { get; set; }
|
||||
public Guid? ResponseDeviceId { get; set; }
|
||||
[MaxLength(25)]
|
||||
public string AccessCode { get; set; }
|
||||
|
@ -164,6 +164,7 @@ public class AuthRequestService : IAuthRequestService
|
||||
RequestDeviceIdentifier = model.DeviceIdentifier,
|
||||
RequestDeviceType = _currentContext.DeviceType.Value,
|
||||
RequestIpAddress = _currentContext.IpAddress,
|
||||
RequestCountryName = _currentContext.CountryName,
|
||||
AccessCode = model.AccessCode,
|
||||
PublicKey = model.PublicKey,
|
||||
UserId = user.Id,
|
||||
@ -176,12 +177,7 @@ public class AuthRequestService : IAuthRequestService
|
||||
|
||||
public async Task<AuthRequest> UpdateAuthRequestAsync(Guid authRequestId, Guid currentUserId, AuthRequestUpdateRequestModel model)
|
||||
{
|
||||
var authRequest = await _authRequestRepository.GetByIdAsync(authRequestId);
|
||||
|
||||
if (authRequest == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
var authRequest = await _authRequestRepository.GetByIdAsync(authRequestId) ?? throw new NotFoundException();
|
||||
|
||||
// Once Approval/Disapproval has been set, this AuthRequest should not be updated again.
|
||||
if (authRequest.Approved is not null)
|
||||
|
@ -30,6 +30,7 @@ public class CurrentContext : ICurrentContext
|
||||
public virtual string DeviceIdentifier { get; set; }
|
||||
public virtual DeviceType? DeviceType { get; set; }
|
||||
public virtual string IpAddress { get; set; }
|
||||
public virtual string CountryName { get; set; }
|
||||
public virtual List<CurrentContextOrganization> Organizations { get; set; }
|
||||
public virtual List<CurrentContextProvider> Providers { get; set; }
|
||||
public virtual Guid? InstallationId { get; set; }
|
||||
@ -104,6 +105,12 @@ public class CurrentContext : ICurrentContext
|
||||
{
|
||||
ClientVersionIsPrerelease = clientVersionIsPrerelease == "1";
|
||||
}
|
||||
|
||||
if (httpContext.Request.Headers.TryGetValue("country-name", out var countryName))
|
||||
{
|
||||
CountryName = countryName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async virtual Task BuildAsync(ClaimsPrincipal user, GlobalSettings globalSettings)
|
||||
|
@ -20,6 +20,7 @@ public interface ICurrentContext
|
||||
string DeviceIdentifier { get; set; }
|
||||
DeviceType? DeviceType { get; set; }
|
||||
string IpAddress { get; set; }
|
||||
string CountryName { get; set; }
|
||||
List<CurrentContextOrganization> Organizations { get; set; }
|
||||
Guid? InstallationId { get; set; }
|
||||
Guid? OrganizationId { get; set; }
|
||||
|
Reference in New Issue
Block a user