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:
parent
b2f41d2140
commit
e05fce18bd
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user