Duo-API Bash C

2024-09-27 21:23:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Curl来执行duoapi的调用。在

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

文档说将creds作为请求的HMAC密钥传递,但现在确定如何实现这一点。在

到目前为止我得到的是:

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"

它回来了

^{pr2}$

有人能给我指出正确的方向吗。如果不是在Python中。在


Tags: key文档httpscomdocsauthentication密钥curl
2条回答

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

尝试:

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。在

第二个,序列错误mean

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

您需要添加丢失的Date头,这是authenticator所必需的。在

如果有人无意中发现了这一点,我的想法是:

#!/bin/bash -u

FORM="Content-Type: application/x-www-form-urlencoded"
NOW=$(date -R)

#get these from the Duo Admin interface
INT="<integration key>"
KEY="<secret passcode>"
API="<api host>.duosecurity.com"

URL="/auth/v2/check"
REQ="$NOW\nGET\n$API\n$URL\n"

#could also use awk here, or the  binary mode as suggested elsewhere
HMAC=$(echo -n "$REQ" | openssl sha1 -hmac "$KEY" | cut -d" " -f 2)

AUTH=$(echo -n "$INT:$HMAC" | base64 -w0)

curl -s -H "Date: $NOW" -H $FORM -H "Authorization: Basic $AUTH" https://$API$URL

运行此操作将产生:

{"response": {"time": 1539726254}, "stat": "OK"}

参考号:Duo Api docs section on authentication

相关问题 更多 >

    热门问题