【问题标题】:HMAC protected API and Postman requestHMAC 保护的 API 和 Postman 请求
【发布时间】:2021-08-22 01:45:24
【问题描述】:

我正在尝试针对受 HMAC 保护的 API 发出请求。

我可以使用 HTTPie 的 HMAC 身份验证插件成功发送请求,如下所示:

http --auth-type=hmackey --auth="key1:secret1" api_url

但是,我通过 Postman 发出请求没有任何成功。我正在关注下面的链接,该链接解释了如何使用预请求脚本,但我总是收到 401:

https://github.com/acquia/http-hmac-postman

有什么想法吗?

【问题讨论】:

    标签: postman hmac httpie


    【解决方案1】:

    如果您想为 post 请求创建一个 hmac 并将其设置为 header,只需在 pre-request 脚本中使用如下cryptoJs。

    const secret = 'your_secret';
    
    var hash = CryptoJS.HmacSHA256(pm.request.body.toString(), secret);
    var hashBase64 = CryptoJS.enc.Base64.stringify(hash);
    
    console.log(hashBase64);
    
    //set it to the environment variable
    pm.environment.set("HmacContentSha", "hashBase64");
    
    

    环境变量HmacContentSha需要传入请求头。

    【讨论】:

    • 我还需要设置访问密钥/api密钥和hmac领域,不是吗?
    • 是的,这取决于 api 要求。
    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 2014-11-19
    • 1970-01-01
    • 2018-11-03
    • 1970-01-01
    • 2022-09-23
    • 2022-07-04
    • 2018-06-04
    相关资源
    最近更新 更多