简体   繁体   English

使用 AWS 签名在 HTTParty 中重新创建邮递员发布请求

[英]Recreating postman post request in HTTParty with AWS signature

I have a custom API that needs to pass in an AWS access key, secret key, and region.我有一个自定义 API,需要传入 AWS 访问密钥、秘密密钥和区域。 I'm able to generate results from the post requests in Postman when I place these credentials in Authorization headers under AWS signature type.当我将这些凭证放在 AWS 签名类型下的 Authorization 标头中时,我能够从 Postman 中的 post 请求生成结果。 But I'm not sure the proper syntax to pass in for HTTParty in ruby.但我不确定在 ruby​​ 中为 HTTParty 传递的正确语法。

This is my current request expression:这是我当前的请求表达式:

response = HTTParty.post(BASE_URL, :body => data.to_json, :headers => {'Content-Type' => 'application/json'})

All examples I see are Authorization passing in a token.我看到的所有示例都是传入令牌的授权。 But in postman I'm passing the access key, secret key and region.但是在邮递员中,我正在传递访问密钥、秘密密钥和区域。 Do I need to generate a token before this?在此之前我需要生成令牌吗? If so, how?如果是这样,如何?

AWS has a ruby gem for this, aws-sigv4 (assuming that's the version you need in your case, double check) that allows you to pass in your credentials, region, and request to create a signature.为此,AWS 有一个 ruby​​ gem,aws-sigv4(假设这是您需要的版本,请仔细检查),它允许您传入您的凭证、区域和请求以创建签名。 It returns a hash of headers that act as its signature, which you can pass to HTTParty with the rest of the request details.它返回作为其签名的标头哈希,您可以将其与其余请求详细信息一起传递给 HTTParty。

https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Sigv4/Signer.html https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Sigv4/Signer.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM