1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

[SG-686] Correctly format AuthRequestResponse.Origin (#2325)

* Remove hardcoded URL case from AuthRequestResponse

* Just use URI host for AuthRequestResponse.Origin
This commit is contained in:
Addison Beck 2022-10-04 11:06:01 -04:00 committed by GitHub
parent 8325f0eed4
commit 54354237ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -46,7 +46,7 @@ public class AuthRequestsController : Controller
{
var userId = _userService.GetProperUserId(User).Value;
var authRequests = await _authRequestRepository.GetManyByUserIdAsync(userId);
var responses = authRequests.Select(a => new AuthRequestResponseModel(a, _globalSettings)).ToList();
var responses = authRequests.Select(a => new AuthRequestResponseModel(a, _globalSettings.BaseServiceUri.Vault)).ToList();
return new ListResponseModel<AuthRequestResponseModel>(responses);
}
@ -60,7 +60,7 @@ public class AuthRequestsController : Controller
throw new NotFoundException();
}
return new AuthRequestResponseModel(authRequest, _globalSettings);
return new AuthRequestResponseModel(authRequest, _globalSettings.BaseServiceUri.Vault);
}
[HttpGet("{id}/response")]
@ -73,7 +73,7 @@ public class AuthRequestsController : Controller
throw new NotFoundException();
}
return new AuthRequestResponseModel(authRequest, _globalSettings);
return new AuthRequestResponseModel(authRequest, _globalSettings.BaseServiceUri.Vault);
}
[HttpPost("")]
@ -111,7 +111,7 @@ public class AuthRequestsController : Controller
};
authRequest = await _authRequestRepository.CreateAsync(authRequest);
await _pushNotificationService.PushAuthRequestAsync(authRequest);
var r = new AuthRequestResponseModel(authRequest, _globalSettings);
var r = new AuthRequestResponseModel(authRequest, _globalSettings.BaseServiceUri.Vault);
return r;
}
@ -141,6 +141,6 @@ public class AuthRequestsController : Controller
await _pushNotificationService.PushAuthRequestResponseAsync(authRequest);
}
return new AuthRequestResponseModel(authRequest, _globalSettings);
return new AuthRequestResponseModel(authRequest, _globalSettings.BaseServiceUri.Vault);
}
}

View File

@ -3,13 +3,12 @@ using System.Reflection;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Models.Api;
using Bit.Core.Settings;
namespace Bit.Api.Models.Response;
public class AuthRequestResponseModel : ResponseModel
{
public AuthRequestResponseModel(AuthRequest authRequest, IGlobalSettings globalSettings, string obj = "auth-request")
public AuthRequestResponseModel(AuthRequest authRequest, string vaultUri, string obj = "auth-request")
: base(obj)
{
if (authRequest == null)
@ -28,7 +27,7 @@ public class AuthRequestResponseModel : ResponseModel
CreationDate = authRequest.CreationDate;
RequestApproved = !string.IsNullOrWhiteSpace(Key) &&
(authRequest.Type == AuthRequestType.Unlock || !string.IsNullOrWhiteSpace(MasterPasswordHash));
Origin = globalSettings.SelfHosted ? globalSettings.BaseServiceUri.Vault : "bitwarden.com";
Origin = new Uri(vaultUri).Host;
}
public string Id { get; set; }