1#include <userver/s3api/authenticators/access_key.hpp>
3#include <userver/s3api/authenticators/utils.hpp>
6#include <unordered_map>
12std::unordered_map<std::string, std::string>
AccessKey::Auth(
const Request& request)
const {
16 static const std::string kDate{
"Date"};
17 static const std::string kContentMd5{
"Content-MD5"};
18 static const std::string kAuthorization{
"Authorization"};
20 std::optional<std::string> header_content_md5;
22 if (!request.body.empty()) {
23 header_content_md5 = MakeHeaderContentMd5(request.body);
26 auto header_date = MakeHeaderDate();
27 auto string_to_sign = MakeStringToSign(request, header_date, header_content_md5);
29 std::unordered_map<std::string, std::string> auth_headers{
30 {kDate, std::move(header_date)},
31 {kAuthorization, MakeHeaderAuthorization(string_to_sign, access_key_, secret_key_)}};
33 if (header_content_md5) {
34 auth_headers.emplace(kContentMd5, std::move(*header_content_md5));
40std::unordered_map<std::string, std::string>
AccessKey::Sign(
const Request& request, time_t expires)
const {
41 static const std::string kExpires{
"Expires"};
42 static const std::string kSignature{
"Signature"};
43 static const std::string kAWSAccessKeyId{
"AWSAccessKeyId"};
45 const auto param_expires = std::to_string(expires);
46 const auto string_to_sign = MakeStringToSign(request, param_expires, std::nullopt);
48 std::unordered_map<std::string, std::string> sign_params{
49 {kExpires, std::move(param_expires)},
50 {kAWSAccessKeyId, access_key_},
51 {kSignature, MakeSignature(string_to_sign, secret_key_)}};