mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
check duo config with duo's api
This commit is contained in:
parent
1a856fb2ab
commit
3588db947a
@ -12,6 +12,7 @@ using System.Linq;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.Core.Utilities.Duo;
|
||||
|
||||
namespace Bit.Api.Controllers
|
||||
{
|
||||
@ -143,6 +144,16 @@ namespace Bit.Api.Controllers
|
||||
public async Task<TwoFactorDuoResponseModel> PutDuo([FromBody]UpdateTwoFactorDuoRequestModel model)
|
||||
{
|
||||
var user = await CheckAsync(model.MasterPasswordHash, true);
|
||||
try
|
||||
{
|
||||
var duoApi = new DuoApi(model.IntegrationKey, model.SecretKey, model.Host);
|
||||
duoApi.JSONApiCall<object>("GET", "/auth/v2/check");
|
||||
}
|
||||
catch(DuoException)
|
||||
{
|
||||
throw new BadRequestException("Duo configuration settings are not valid. Please re-check the Duo Admin panel.");
|
||||
}
|
||||
|
||||
model.ToUser(user);
|
||||
await _userService.UpdateTwoFactorProviderAsync(user, TwoFactorProviderType.Duo);
|
||||
var response = new TwoFactorDuoResponseModel(user);
|
||||
|
@ -79,7 +79,7 @@ namespace Bit.Core.Utilities.Duo
|
||||
return string.Concat("Basic ", Encode64(auth));
|
||||
}
|
||||
|
||||
public string ApiCall(string method, string path, Dictionary<string, string> parameters)
|
||||
public string ApiCall(string method, string path, Dictionary<string, string> parameters = null)
|
||||
{
|
||||
return ApiCall(method, path, parameters, 0, out var statusCode);
|
||||
}
|
||||
@ -94,6 +94,11 @@ namespace Bit.Core.Utilities.Duo
|
||||
public string ApiCall(string method, string path, Dictionary<string, string> parameters, int timeout,
|
||||
out HttpStatusCode statusCode)
|
||||
{
|
||||
if(parameters == null)
|
||||
{
|
||||
parameters = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
var canonParams = CanonicalizeParams(parameters);
|
||||
var query = string.Empty;
|
||||
if(!method.Equals("POST") && !method.Equals("PUT"))
|
||||
@ -151,7 +156,7 @@ namespace Bit.Core.Utilities.Duo
|
||||
}
|
||||
}
|
||||
|
||||
public T JSONApiCall<T>(string method, string path, Dictionary<string, string> parameters)
|
||||
public T JSONApiCall<T>(string method, string path, Dictionary<string, string> parameters = null)
|
||||
where T : class
|
||||
{
|
||||
return JSONApiCall<T>(method, path, parameters, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user