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

标签 linux shell

我正在尝试使用 $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/

相关文章:

php - 在此服务器上找不到请求的 URL/practice/public/admin

c - 如果在没有 "__attribute__(align(8))"的情况下声明结构,如何生成警告

linux - 使用 shell 脚本添加和维护跨文件的序列连续性

linux - 试图将 700,000 个数据与 1500 万个数据删除

linux - : a=1, let a=1, ((a=1)) 这三种赋值方式有区别吗

c - 可能是多线程环境下的 Errno 描述

linux - 针对嵌入式 Linux 设备的存储高效远程文件完整性检查

c++ - 当另一个线程正在读/写 fd 时,我可以调用 posix_fadvise 吗?

bash - 检查 Docker 中的 SSH 服务是否启动的脚本

linux - CLI : Exit code on confirmation question? 1 或 0