AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
SigV4Signer.h
1
5#pragma once
6
7#include <smithy/identity/signer/AwsSignerBase.h>
8#include <smithy/identity/identity/AwsCredentialIdentityBase.h>
9
10#include <aws/core/auth/signer/AWSAuthV4Signer.h>
11
12#include <aws/core/auth/AWSCredentials.h>
13
14namespace smithy {
19 class AwsSigV4Signer : public AwsSignerBase<AwsCredentialIdentityBase> {
20
21 public:
23 explicit AwsSigV4Signer(const Aws::String& serviceName, const Aws::String& region)
24 : m_serviceName(serviceName),
25 m_region(region),
26 legacySigner(nullptr, serviceName.c_str(), region, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Always)
27 {
28 }
29
30 SigningFutureOutcome sign(std::shared_ptr<HttpRequest> httpRequest, const AwsCredentialIdentityBase& identity, SigningProperties properties) override
31 {
32 const auto legacyCreds = [&identity]() -> Aws::Auth::AWSCredentials {
33 if(identity.sessionToken().has_value() && identity.expiration().has_value())
34 {
35 return {identity.accessKeyId(), identity.secretAccessKey(), *identity.sessionToken(), *identity.expiration()};
36 }
37 if(identity.sessionToken().has_value())
38 {
39 return {identity.accessKeyId(), identity.secretAccessKey(), *identity.sessionToken()};
40 }
41 return {identity.accessKeyId(), identity.secretAccessKey()};
42 }();
43
44
45
46 auto signPayloadIt = properties.find("SignPayload");
47 bool signPayload = signPayloadIt != properties.end() ? signPayloadIt->second.get<Aws::String>() == "true" : false;
48
49 assert(httpRequest);
50 bool success = legacySigner.SignRequestWithCreds(*httpRequest, legacyCreds, m_region.c_str(), m_serviceName.c_str(), signPayload);
51 if (success)
52 {
53 return SigningFutureOutcome(std::move(httpRequest));
54 }
55 return SigningError(Aws::Client::CoreErrors::MEMORY_ALLOCATION, "", "Failed to sign the request with sigv4", false);
56 }
57
58 virtual ~AwsSigV4Signer() {};
59 protected:
63 };
64}
virtual Aws::String accessKeyId() const =0
virtual Aws::Crt::Optional< AwsIdentity::DateTime > expiration() const override=0
virtual Aws::String secretAccessKey() const =0
virtual Aws::Crt::Optional< Aws::String > sessionToken() const =0
Aws::String m_serviceName
Definition SigV4Signer.h:60
Aws::Client::AWSAuthV4Signer legacySigner
Definition SigV4Signer.h:62
SigningFutureOutcome sign(std::shared_ptr< HttpRequest > httpRequest, const AwsCredentialIdentityBase &identity, SigningProperties properties) override
Definition SigV4Signer.h:30
AwsSigV4Signer(const Aws::String &serviceName, const Aws::String &region)
Definition SigV4Signer.h:23
Aws::Client::AWSError< Aws::Client::CoreErrors > SigningError
Aws::Utils::FutureOutcome< std::shared_ptr< HttpRequest >, SigningError > SigningFutureOutcome
Aws::UnorderedMap< Aws::String, Aws::Crt::Variant< Aws::String, bool > > SigningProperties
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97