Skip to main content
 首页 » 编程设计

python之Duo API Bash 调用

2025年01月19日13youxin

我正在尝试使用 Curl 通过 DUO API 执行调用。

我试着在这里查看他们的文档:https://duo.com/docs/adminapi#authentication

文档说将凭据作为请求的 HMAC key 传递,但现在确定如何实现它。

这是我到目前为止得到的:

curl --request GET \ 
     --header 'Authorization: Basic 'Integration key:Secret key'' \ 
     --header "Content-Type: application/x-www-form-urlencoded" \ 
     "https://api-12345678.duosecurity.com/auth/v2/check" 

哪个返回

{"code": 40101, "message": "Missing request credentials", "stat": "FAIL"} 

有人能为我指出 Bash 中的示例的正确方向吗?如果不是在 Python 中。

请您参考如下方法:

首先,您的请求格式似乎不正确,因为 Integration key:Secret key'' 在 header 之外(查看问题中突出显示语法的方式)。

尝试:

curl --request GET \ 
     --header 'Authorization: Basic' \ 
     --header 'Integration key: Secret key' \ 
     --header 'Date: Tue, 21 Aug 2012 17:29:18 -0000' \ 
     --header "Content-Type: application/x-www-form-urlencoded" \ 
     "https://api-12345678.duosecurity.com/auth/v2/check" 

像 Integration key 这样的标题名称带有空格和小写字母的情况并不常见,因此您可能需要尝试变体,例如 Integration-Key 。

二,401xx系列错误mean:

401 The “Authorization”, “Date”, and/or “Content-Type” headers were missing or invalid.

您需要添加 authenticator 所需的缺少的 Date header 。