gpt4 book ai didi

linux - 无法替换 curl 中授权 header 值中的自定义变量

转载 作者:太空宇宙 更新时间:2023-11-04 10:07:44 28 4
gpt4 key购买 nike

我正在尝试使用 $timestamp 并生成哈希。我看到 $timestamp 值没有被分配,它总是相同的。

我的要求:--

curl  -H "Authorization:EG1-HMAC-SHA256;timestamp=$(date +%Y%m%dT%H:%M:%S+0000);nonce=`cat /proc/sys/kernel/random/uuid`;signature=$(echo -n $timestamp | openssl dgst -binary -sha256 -hmac '+abhishek' | openssl enc -base64)"  https://test.com/abcd/v1/test/123/impulse -vv

输出[请求授权 header ]

Authorization:EG1-HMAC-SHA256;timestamp=20180701T12:33:56+0000;nonce=8ed3eddf-27ac-4f19-ba81-0ecd07aeb50a;signature=6vMTTitxbU0/3DRXAEPej4HyqQTG+V/F5NLGNcqG2ys=

20180701T12:33:56+0000 是我想在 '$(echo -n $timestamp' 中替换的正确值,但它没有发生。$timestamp 在 curl 命令执行后根本没有改变。

测试:--我最初将 0 分配给时间戳。执行了上面的 curl 命令。检查了 echo $timestamp,还是一样[0]。

我是 linux shell 的新手。任何帮助将不胜感激。

最佳答案

当你清理它并将它分解成多行时,它就变得简单了:

url="https://test.com/abcd/v1/test/123/impulse"
timestamp="$(date +%Y%m%dT%H:%M:%S+0000)"
nonce="$(cat /proc/sys/kernel/random/uuid)"
signature="$(openssl dgst -binary -sha256 -hmac '+abhishek' <<< "${timestamp}" \
| openssl enc -base64)"

auth_header="Authorization:EG1-HMAC-SHA256"
auth_header="${auth_header};timestamp=${timestamp}"
auth_header="${auth_header};nonce=${nonce}"
auth_header="${auth_header};signature=${signature}"

curl -H "${auth_header}" "${url}" -vv

关于linux - 无法替换 curl 中授权 header 值中的自定义变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51123433/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com