mirror of
https://github.com/bitwarden/server.git
synced 2025-02-18 02:11:22 +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);
|
var res = ApiCall(method, path, parameters, timeout, out var statusCode);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// TODO: We should deserialize this into our own DTO and not work on dictionaries.
|
||||||
var dict = JsonSerializer.Deserialize<Dictionary<string, object>>(res);
|
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?;
|
messageDetail = dict["message_detail"].ToString();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
throw new ApiException(code, (int)statusCode, dict["message"].ToString(), messageDetail);
|
||||||
}
|
}
|
||||||
catch (ApiException)
|
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)
|
private string HmacSign(string data)
|
||||||
{
|
{
|
||||||
var keyBytes = Encoding.ASCII.GetBytes(_skey);
|
var keyBytes = Encoding.ASCII.GetBytes(_skey);
|
||||||
|
Loading…
Reference in New Issue
Block a user