Skip to content

Commit 54e3f6f

Browse files
committed
Multi auth request level resolution
1 parent c9374f0 commit 54e3f6f

36 files changed

+500
-65
lines changed

src/aws-cpp-sdk-core/include/aws/core/AmazonWebServiceRequest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <aws/core/utils/memory/stl/AWSString.h>
2020
#include <aws/core/utils/stream/ResponseStream.h>
2121
#include <aws/core/endpoint/internal/AWSEndpointAttribute.h>
22+
#include <smithy/identity/auth/AuthSchemeOption.h>
2223

2324
namespace Aws
2425
{
@@ -231,6 +232,8 @@ namespace Aws
231232
RetryContext GetRetryContext() const { return m_retryContext; }
232233

233234
void SetRetryContext(const RetryContext& context) const { m_retryContext = context; }
235+
236+
virtual Aws::Vector<smithy::AuthSchemeOption> GetRequestSpecificSupportedAuth() const { return {}; }
234237
protected:
235238
/**
236239
* Default does nothing. Override this to convert what would otherwise be the payload of the

src/aws-cpp-sdk-core/include/aws/core/auth/AWSAuthSigner.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
#include <aws/core/auth/signer/AWSAuthEventStreamV4Signer.h>
1313
#include <aws/core/auth/signer/AWSNullSigner.h>
1414

15+
#include <smithy/identity/auth/built-in/NoAuthScheme.h>
16+
#include <smithy/identity/auth/built-in/NoAuthSchemeOption.h>
17+
1518
// This is a header that represents old legacy all-in-one header to maintain backward compatibility

src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClient.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ namespace client
188188
}
189189
}
190190

191-
Aws::Vector<AuthSchemeOption> authSchemeOptions = m_authSchemeResolver->resolveAuthScheme(identityParams);
191+
Aws::Vector<AuthSchemeOption> authSchemeOptions = ctx.m_authResolver == nullptr ? m_authSchemeResolver->resolveAuthScheme(identityParams) : ctx.m_authResolver->resolveAuthScheme(identityParams);
192192

193193
auto authSchemeOptionIt = std::find_if(authSchemeOptions.begin(), authSchemeOptions.end(),
194194
[this](const AuthSchemeOption& opt)
@@ -352,15 +352,18 @@ namespace client
352352

353353
GetContextEndpointParametersOutcome GetContextEndpointParametersImpl(const AwsSmithyClientAsyncRequestContext& ctx) const {
354354
Aws::Vector<Aws::Endpoint::EndpointParameter> endpointParameters;
355-
const auto resolvedAccountId = ctx.m_awsIdentity->accountId();
356-
const auto resolvedNonEmptyAccountId = resolvedAccountId.has_value() && !resolvedAccountId.value().empty();
357-
// Set user agent if account ID was resolved in identity provider
358-
if (resolvedNonEmptyAccountId) {
359-
ctx.m_pRequest->AddUserAgentFeature(Aws::Client::UserAgentFeature::RESOLVED_ACCOUNT_ID);
360-
}
361-
// Only set EP param if client configuration does not have a configured account ID and we resolved a account id
362-
if (resolvedNonEmptyAccountId && m_clientConfiguration.accountId.empty()) {
363-
endpointParameters.emplace_back("AccountId", resolvedAccountId.value(), Aws::Endpoint::EndpointParameter::ParameterOrigin::OPERATION_CONTEXT);
355+
//nullptr indicates we're using noAuth and therefore there is no identity
356+
if (ctx.m_awsIdentity != nullptr) {
357+
const auto resolvedAccountId = ctx.m_awsIdentity->accountId();
358+
const auto resolvedNonEmptyAccountId = resolvedAccountId.has_value() && !resolvedAccountId.value().empty();
359+
// Set user agent if account ID was resolved in identity provider
360+
if (resolvedNonEmptyAccountId) {
361+
ctx.m_pRequest->AddUserAgentFeature(Aws::Client::UserAgentFeature::RESOLVED_ACCOUNT_ID);
362+
}
363+
// Only set EP param if client configuration does not have a configured account ID and we resolved a account id
364+
if (resolvedNonEmptyAccountId && m_clientConfiguration.accountId.empty()) {
365+
endpointParameters.emplace_back("AccountId", resolvedAccountId.value(), Aws::Endpoint::EndpointParameter::ParameterOrigin::OPERATION_CONTEXT);
366+
}
364367
}
365368
return endpointParameters;
366369
}

src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClientAsyncRequestContext.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <smithy/Smithy_EXPORTS.h>
1313
#include <smithy/identity/auth/AuthSchemeOption.h>
1414
#include <smithy/interceptor/InterceptorContext.h>
15+
#include <smithy/identity/auth/AuthSchemeResolverBase.h>
1516

1617
namespace smithy
1718
{
@@ -71,18 +72,21 @@ namespace smithy
7172
std::shared_ptr<Aws::Utils::Threading::Executor> m_pExecutor;
7273
std::shared_ptr<interceptor::InterceptorContext> m_interceptorContext;
7374
std::shared_ptr<smithy::AwsIdentity> m_awsIdentity;
75+
std::shared_ptr<smithy::AuthSchemeResolverBase<>> m_authResolver;
7476

7577
AwsSmithyClientAsyncRequestContext() = default;
7678

7779
AwsSmithyClientAsyncRequestContext(
7880
Aws::AmazonWebServiceRequest const * const request,
7981
const char* requestName,
80-
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor):
82+
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor,
83+
std::shared_ptr<smithy::AuthSchemeResolverBase<>> authResolver):
8184
m_invocationId{Aws::Utils::UUID::PseudoRandomUUID()},
8285
m_pRequest{request},
8386
m_requestName{requestName ? requestName : m_pRequest ? m_pRequest->GetServiceRequestName() : ""},
8487
m_retryCount{0},
85-
m_pExecutor{pExecutor}
88+
m_pExecutor{pExecutor},
89+
m_authResolver{authResolver}
8690
{
8791

8892
}

src/aws-cpp-sdk-core/include/smithy/identity/auth/built-in/BearerTokenAuthSchemeOption.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ struct BearerTokenAuthSchemeOption
1212
static AuthSchemeOption bearerTokenAuthSchemeOption;
1313
};
1414

15-
AuthSchemeOption BearerTokenAuthSchemeOption::bearerTokenAuthSchemeOption =
15+
inline AuthSchemeOption BearerTokenAuthSchemeOption::bearerTokenAuthSchemeOption =
1616
AuthSchemeOption("smithy.api#HTTPBearerAuth");
1717
} // namespace smithy
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/auth/AuthScheme.h>
8+
#include <smithy/identity/auth/built-in/NoAuthSchemeOption.h>
9+
10+
#include <smithy/identity/identity/AwsCredentialIdentityBase.h>
11+
#include <smithy/identity/signer/built-in/NoAuthSigner.h>
12+
13+
namespace smithy {
14+
constexpr char NOAUTH[] = "smithy.api#noAuth";
15+
16+
class NoAuthScheme : public AuthScheme<AwsCredentialIdentityBase>
17+
{
18+
public:
19+
using AwsCredentialIdentityResolverT = IdentityResolverBase<IdentityT>;
20+
using AwsCredentialSignerT = AwsSignerBase<IdentityT>;
21+
22+
explicit NoAuthScheme()
23+
: AuthScheme(NOAUTH),
24+
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")}
25+
{
26+
assert(m_signer);
27+
}
28+
29+
explicit NoAuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver,
30+
const Aws::String& serviceName,
31+
const Aws::String& region)
32+
: AuthScheme(NOAUTH),
33+
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")}
34+
{
35+
AWS_UNREFERENCED_PARAM(identityResolver);
36+
AWS_UNREFERENCED_PARAM(serviceName);
37+
AWS_UNREFERENCED_PARAM(region);
38+
assert(m_signer);
39+
}
40+
41+
explicit NoAuthScheme(const Aws::String& serviceName,
42+
const Aws::String& region)
43+
: NoAuthScheme(nullptr, serviceName, region)
44+
{
45+
assert(m_signer);
46+
}
47+
48+
//legacy constructors
49+
explicit NoAuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver, const Aws::String& serviceName, const Aws::String& region, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy policy, bool urlEscape)
50+
: AuthScheme(NOAUTH),
51+
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")}
52+
{
53+
AWS_UNREFERENCED_PARAM(identityResolver);
54+
AWS_UNREFERENCED_PARAM(serviceName);
55+
AWS_UNREFERENCED_PARAM(region);
56+
AWS_UNREFERENCED_PARAM(policy);
57+
AWS_UNREFERENCED_PARAM(urlEscape);
58+
assert(m_signer);
59+
}
60+
61+
virtual ~NoAuthScheme() = default;
62+
63+
std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver() override
64+
{
65+
return nullptr;
66+
}
67+
68+
std::shared_ptr<AwsCredentialSignerT> signer() override
69+
{
70+
return m_signer;
71+
}
72+
73+
protected:
74+
std::shared_ptr<AwsCredentialSignerT> m_signer;
75+
};
76+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/Smithy_EXPORTS.h>
8+
#include <smithy/identity/auth/AuthSchemeOption.h>
9+
10+
namespace smithy {
11+
struct NoAuthSchemeOption
12+
{
13+
static SMITHY_API AuthSchemeOption noAuthSchemeOption;
14+
};
15+
}

src/aws-cpp-sdk-core/include/smithy/identity/identity/impl/AwsBearerTokenIdentityImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#include <smithy/identity/identity/AwsBearerTokenIdentity.h>
99

1010
namespace smithy {
11-
const Aws::String &AwsBearerTokenIdentity::token() const { return m_token; }
11+
inline const Aws::String &AwsBearerTokenIdentity::token() const { return m_token; }
1212

13-
Aws::Crt::Optional<AwsIdentity::DateTime>
13+
inline Aws::Crt::Optional<AwsIdentity::DateTime>
1414
AwsBearerTokenIdentity::expiration() const
1515
{
1616
return m_expiration;

src/aws-cpp-sdk-core/include/smithy/identity/resolver/AwsBearerTokenIdentityResolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class DefaultAwsBearerTokenIdentityResolver
104104
: AwsBearerTokenIdentityResolver(Aws::Vector<std::shared_ptr<Aws::Auth::AWSBearerTokenProviderBase>>{
105105
Aws::MakeShared<Aws::Auth::SSOBearerTokenProvider>("SSOBearerTokenProvider")}){};
106106
};
107-
const char
107+
inline const char
108108
AwsBearerTokenIdentityResolver::BEARER_TOKEN_PROVIDER_CHAIN_LOG_TAG[] =
109109
"BearerTokenProvider";
110110

src/aws-cpp-sdk-core/include/smithy/identity/signer/built-in/BearerTokenSigner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ class BearerTokenSigner : public AwsSignerBase<AwsBearerTokenIdentityBase>
7171
Aws::String m_region;
7272
};
7373

74-
const char BearerTokenSigner::LOGGING_TAG[] = "BearerTokenSigner";
74+
inline const char BearerTokenSigner::LOGGING_TAG[] = "BearerTokenSigner";
7575
} // namespace smithy

0 commit comments

Comments
 (0)