AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
BearerTokenSigner.h
1
6#pragma once
7
8#include <smithy/identity/identity/AwsBearerTokenIdentityBase.h>
9#include <smithy/identity/signer/AwsSignerBase.h>
10
11#include <aws/core/auth/signer/AWSAuthSignerHelper.h>
12#include <aws/core/http/HttpRequest.h>
13#include <aws/crt/http/HttpConnection.h>
14#include <aws/crt/http/HttpRequestResponse.h>
15
16namespace smithy
17{
18static const char AUTHORIZATION_HEADER[] = "authorization";
19
20class BearerTokenSigner : public AwsSignerBase<AwsBearerTokenIdentityBase>
21{
22
23 public:
24 static const char LOGGING_TAG[];
25
28 explicit BearerTokenSigner(const Aws::String &serviceName,
29 const Aws::String &region)
30 : m_serviceName(serviceName), m_region(region)
31 {
32 }
33
35 sign(std::shared_ptr<HttpRequest> httpRequest,
37 SigningProperties properties) override
38 {
39 AWS_UNREFERENCED_PARAM(properties);
40
41 if (Aws::Http::Scheme::HTTPS != httpRequest->GetUri().GetScheme())
42 {
43 // Clients MUST always use TLS (https) or equivalent transport
44 // security when making requests with bearer tokens.
45 // https://datatracker.ietf.org/doc/html/rfc6750
46 AWS_LOGSTREAM_ERROR(
48 "HTTPS scheme must be used with a bearer token authorization");
49 return SigningError(
51 "Failed to sign the request with bearer", false);
52 }
53
54 httpRequest->SetHeaderValue(AUTHORIZATION_HEADER,
55 "Bearer " + identity.token());
56
57 return SigningFutureOutcome(std::move(httpRequest));
58 }
59
60 virtual ~BearerTokenSigner(){};
61
62 protected:
65};
66
67const char BearerTokenSigner::LOGGING_TAG[] = "BearerTokenSigner";
68} // namespace smithy
virtual const Aws::String & token() const =0
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
static const char LOGGING_TAG[]
SigningFutureOutcome sign(std::shared_ptr< HttpRequest > httpRequest, const smithy::AwsBearerTokenIdentityBase &identity, SigningProperties properties) override
BearerTokenSigner(const Aws::String &serviceName, const Aws::String &region)
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
static const char AUTHORIZATION_HEADER[]