AWS SDK for C++

AWS SDK for C++ Version 1.11.827

Loading...
Searching...
No Matches
AuthSchemeResolverBase.h
1
5#pragma once
6
7#include <smithy/identity/auth/AuthSchemeOption.h>
8#include <smithy/identity/signer/AwsSignerBase.h>
9
10#include <aws/crt/Variant.h>
11#include <aws/core/utils/memory/stl/AWSVector.h>
12
13namespace smithy {
14
15static const char SIGV4_PREFERENCE[] = "sigv4";
16static const char SIGV4A_PREFERENCE[] = "sigv4a";
17static const char BEARER_PREFERENCE[] = "bearer";
18static const char NO_AUTH_PREFERENCE[] = "noauth";
19
20// Global map from auth scheme name (trimmed ID) to full ID for case insensitive lookup
22 std::make_pair(SIGV4_PREFERENCE, "aws.auth#sigv4"),
23 std::make_pair(SIGV4A_PREFERENCE, "aws.auth#sigv4a"),
24 std::make_pair(BEARER_PREFERENCE, "smithy.api#HTTPBearerAuth"),
25 std::make_pair(NO_AUTH_PREFERENCE, "smithy.api#noAuth")
26}};
27
33{
34public:
37 Aws::Crt::Optional<Aws::String> region;
39
40 Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String,
41 bool,
45
46};
47
48template<typename ServiceAuthSchemeParametersT = DefaultAuthSchemeResolverParameters, typename ClientConfigT = Aws::Client::ClientConfiguration>
50{
51public:
52
53 virtual void Init(const ClientConfigT& config) {
54 AWS_UNREFERENCED_PARAM(config);
55 }
56
57 using ServiceAuthSchemeParameters = ServiceAuthSchemeParametersT;
58
59 virtual ~AuthSchemeResolverBase() = default;
60
62 auto options = resolveAuthSchemeImpl(identityProperties);
63 return filterByPreferences(options, identityProperties.authPreferences);
64 }
65
66protected:
68
70 const Aws::Vector<Aws::String>& preferences) {
71 if (preferences.empty()) return options;
72
74 for (const auto& pref : preferences) {
75 auto prefSchemeIt = find_if(AUTH_SCHEME_NAME_TO_ID.begin(), AUTH_SCHEME_NAME_TO_ID.end(), [&](const std::pair<const char*, const char*> &pair) { return Aws::Utils::StringUtils::ToLower(pref.c_str()) == pair.first; });
76 if (prefSchemeIt == AUTH_SCHEME_NAME_TO_ID.end()) continue;
77 for (const auto& option : options) {
78 if (strcmp(option.schemeId, prefSchemeIt->second) == 0) {
79 filtered.push_back(option);
80 break;
81 }
82 }
83 }
84 return filtered.empty() ? options : filtered;
85 }
86};
87}
virtual Aws::Vector< AuthSchemeOption > resolveAuthScheme(const ServiceAuthSchemeParameters &identityProperties)
virtual ~AuthSchemeResolverBase()=default
virtual void Init(const ClientConfigT &config)
virtual Aws::Vector< AuthSchemeOption > filterByPreferences(const Aws::Vector< AuthSchemeOption > &options, const Aws::Vector< Aws::String > &preferences)
virtual Aws::Vector< AuthSchemeOption > resolveAuthSchemeImpl(const ServiceAuthSchemeParameters &identityProperties)=0
ServiceAuthSchemeParametersT ServiceAuthSchemeParameters
Aws::UnorderedMap< Aws::String, Aws::Crt::Variant< Aws::String, bool, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy, Aws::Auth::AWSSigningAlgorithm, Aws::Vector< Aws::String > > > additionalProperties
std::array< T, N > Array
Definition AWSArray.h:11
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
std::vector< T, Aws::Allocator< T > > Vector
Definition AWSVector.h:17
std::unordered_map< K, V, std::hash< K >, std::equal_to< K >, Aws::Allocator< std::pair< const K, V > > > UnorderedMap
Definition AWSMap.h:21
static const char SIGV4_PREFERENCE[]
static const Aws::Array< std::pair< const char *, const char * >, 4 > AUTH_SCHEME_NAME_TO_ID
static const char NO_AUTH_PREFERENCE[]
static const char BEARER_PREFERENCE[]
static const char SIGV4A_PREFERENCE[]