1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

Resolve being unable to configure duo (System.Text.Json) (#1847)

This commit is contained in:
Oscar Hinton 2022-02-09 14:12:31 +01:00 committed by GitHub
parent b2f41d2140
commit e05fce18bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -175,22 +175,21 @@ namespace Bit.Core.Utilities.Duo
var res = ApiCall(method, path, parameters, timeout, out var statusCode);
try
{
// TODO: We should deserialize this into our own DTO and not work on dictionaries.
var dict = JsonSerializer.Deserialize<Dictionary<string, object>>(res);
if (dict["stat"] as string == "OK")
if (dict["stat"].ToString() == "OK")
{
return dict["response"] as T;
return JsonSerializer.Deserialize<T>(dict["response"].ToString());
}
else
var check = ToNullableInt(dict["code"].ToString());
var code = check.GetValueOrDefault(0);
var messageDetail = string.Empty;
if (dict.ContainsKey("message_detail"))
{
var check = dict["code"] as int?;
var code = check.GetValueOrDefault(0);
var messageDetail = string.Empty;
if (dict.ContainsKey("message_detail"))
{
messageDetail = dict["message_detail"] as string;
}
throw new ApiException(code, (int)statusCode, dict["message"] as string, messageDetail);
messageDetail = dict["message_detail"].ToString();
}
throw new ApiException(code, (int)statusCode, dict["message"].ToString(), messageDetail);
}
catch (ApiException)
{
@ -202,6 +201,16 @@ namespace Bit.Core.Utilities.Duo
}
}
private int? ToNullableInt(string s)
{
int i;
if (int.TryParse(s, out i))
{
return i;
}
return null;
}
private string HmacSign(string data)
{
var keyBytes = Encoding.ASCII.GetBytes(_skey);