DUO 管理员身份验证问题

DUO Admin Auth Issues

提问人:Foadi 提问时间:11/22/2022 更新时间:11/22/2022 访问量:410

问:

我正在尝试构建一个自动将用户添加到 DUO 的 C# 应用程序。

文档不清楚如何在线执行此操作。

这是我使用的代码

            var client = new HttpClient();
            var Request = new HttpRequestMessage(HttpMethod.Post, "https://api-2cf9xxxx.duosecurity.com/admin/v1/users");

            Request.Content = new StringContent(string.Empty, Encoding.Unicode, "application/x-www-form-urlencoded");
            Request.Headers.Add("X-Duo-Date", DuoDate);
            Request.Headers.Add("Authorization","Basic " + val);

            Request.Content = new FormUrlEncodedContent(new Dictionary<string, string>
            {{"username:",ADAccountNameStr}});

            Request.Headers.Add("Host", DuoHostname);

            var response = await client.SendAsync(Request,HttpCompletionOption.ResponseHeadersRead);
                        
            var responseContent = await response.Content.ReadAsStringAsync();

这是这个 Request 和标头响应

Tue, 22 Nov 2022 15:19:41 +0000
POST
api-2cxxxxx.duosecurity.com
/admin/v1/users
username:jdoe
Method: POST, RequestUri: 'https://api-2cfxxxxx.duosecurity.com/admin/v1/users', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  X-Duo-Date: Tue, 22 Nov 2022 15:19:41 +0000
  Authorization: Basic RElHVEsxWTBFOERENjdJU0NVNTY6MmM0NWU4MDBhNzkyOGE3YmY5NjBlNDI0MDI3NDZjYzY1Y2MzYzhkYQ==
  Host: api-2cfxxxxxx.duosecurity.com
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 16
}
StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Connection: keep-alive
  Date: Tue, 22 Nov 2022 15:19:41 GMT
  Server: Duo/1.0
  Content-Length: 86
  Content-Type: application/json
}

我得到的错误是

"code": 40103, "message": "Invalid signature in request credentials", "stat": "FAIL"

谁能看出我哪里出了问题,唯一似乎正确的是内容长度。

C# HttpClient DuoSecurity

评论

0赞 Nikita Chayka 11/23/2022
Duo 文档非常清楚地说明了如何构造其 Authentication 标头 - duo.com/docs/adminapi#authentication。你用什么作为你的?val
0赞 Foadi 11/23/2022
检查响应,val is = 到授权后的内容:基本 *
0赞 Nikita Chayka 11/23/2022
我看到了这一点,我的意思是 - 你如何精确计算该值,你没有显示代码中最重要的部分
0赞 Foadi 11/23/2022
System.Text.UTF8Encoding myEncoder = new System.Text.UTF8Encoding();byte[] 键 = myEncoder.GetBytes(secret_key);byte[] 文本 = myEncoder.GetBytes(APIRequest);System.Security.Cryptography.HMACSHA1 myHMACSHA1 = 新
0赞 Foadi 11/23/2022
System.Security.Cryptography.HMACSHA1(密钥);byte[] 哈希代码 = myHMACSHA1.ComputeHash(Text);字符串哈希 = BitConverter.ToString(HashCode)。替换(“-”, “”);string hash1 = 哈希。ToLower();字符串 hmac = client_key + “:” + hash1;var plainTextBytes = System.Text.Encoding.ASCII.GetBytes(hmac);字符串 val = System.Convert.ToBase64String(plainTextBytes);

答: 暂无答案