From 5fd9a53700992f5038290990acbb5a75815dc32c Mon Sep 17 00:00:00 2001 From: Bhavya Sharma Date: Thu, 5 Sep 2024 13:49:41 -0700 Subject: [PATCH 1/2] Added a new CustomSSOCredentialsProvider class that inherits from SSOCredentialsProvider --- .../core/auth/CustomSSOCredentialsProvider.h | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/aws-cpp-sdk-core/include/aws/core/auth/CustomSSOCredentialsProvider.h diff --git a/src/aws-cpp-sdk-core/include/aws/core/auth/CustomSSOCredentialsProvider.h b/src/aws-cpp-sdk-core/include/aws/core/auth/CustomSSOCredentialsProvider.h new file mode 100644 index 00000000000..0a6bf0da6aa --- /dev/null +++ b/src/aws-cpp-sdk-core/include/aws/core/auth/CustomSSOCredentialsProvider.h @@ -0,0 +1,34 @@ +/** +* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once + +#include +#include + +namespace Aws { + namespace Auth { + class AWS_CORE_API CustomSSOCredentialsProvider : public SSOCredentialsProvider { + public: + CustomSSOCredentialsProvider(const Aws::Client::ClientConfiguration& clientConfig) + : SSOCredentialsProvider(), m_clientConfig(clientConfig) + { + } + + void Reload() override { + Aws::Client::ClientConfiguration config = m_clientConfig; + config.scheme = Aws::Http::Scheme::HTTPS; + config.region = m_ssoRegion; + + m_client = Aws::MakeUnique(SSO_CREDENTIALS_PROVIDER_LOG_TAG, config); + + SSOCredentialsProvider::Reload(); + } + + private: + Aws::Client::ClientConfiguration m_clientConfig; + }; + } // namespace Auth +} // namespace Aws \ No newline at end of file From df97ade88935ddbc41e23a5035eb2ca51eff5119 Mon Sep 17 00:00:00 2001 From: Bhavya Sharma Date: Fri, 6 Sep 2024 09:58:27 -0700 Subject: [PATCH 2/2] Added Custom Constructor in SSOCredentialsProvider --- .../include/aws/core/auth/SSOCredentialsProvider.h | 3 +++ .../source/auth/SSOCredentialsProvider.cpp | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/aws-cpp-sdk-core/include/aws/core/auth/SSOCredentialsProvider.h b/src/aws-cpp-sdk-core/include/aws/core/auth/SSOCredentialsProvider.h index 3b476177b9a..ecd318082c7 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/auth/SSOCredentialsProvider.h +++ b/src/aws-cpp-sdk-core/include/aws/core/auth/SSOCredentialsProvider.h @@ -21,6 +21,7 @@ namespace Aws { public: SSOCredentialsProvider(); explicit SSOCredentialsProvider(const Aws::String& profile); + explicit SSOCredentialsProvider(const Aws::Client::ClientConfiguration& clientConfig); /** * Retrieves the credentials if found, otherwise returns empty credential set. */ @@ -42,6 +43,8 @@ namespace Aws { Aws::Utils::DateTime m_expiresAt; // The SSO Token Provider Aws::Auth::SSOBearerTokenProvider m_bearerTokenProvider; + // Custom ClientConfiguration used by the SSOCredentialsClient during Reload() + Aws::Client::ClientConfiguration m_clientConfig; void Reload() override; void RefreshIfExpired(); diff --git a/src/aws-cpp-sdk-core/source/auth/SSOCredentialsProvider.cpp b/src/aws-cpp-sdk-core/source/auth/SSOCredentialsProvider.cpp index 9576e9d9999..9e5d2a95950 100644 --- a/src/aws-cpp-sdk-core/source/auth/SSOCredentialsProvider.cpp +++ b/src/aws-cpp-sdk-core/source/auth/SSOCredentialsProvider.cpp @@ -39,6 +39,13 @@ SSOCredentialsProvider::SSOCredentialsProvider(const Aws::String& profile) : m_p AWS_LOGSTREAM_INFO(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Setting sso credentials provider to read config from " << m_profileToUse); } +SSOCredentialsProvider::SSOCredentialsProvider(const Aws::Client::ClientConfiguration& clientConfig) + : m_profileToUse(GetConfigProfileName()), m_clientConfig(clientConfig) +{ + AWS_LOGSTREAM_INFO(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Setting sso credentials provider to read config from " << m_profileToUse); +} + + AWSCredentials SSOCredentialsProvider::GetAWSCredentials() { RefreshIfExpired(); @@ -80,7 +87,7 @@ void SSOCredentialsProvider::Reload() request.m_ssoRoleName = profile.GetSsoRoleName(); request.m_accessToken = accessToken; - Aws::Client::ClientConfiguration config; + Aws::Client::ClientConfiguration config = m_clientConfig; config.scheme = Aws::Http::Scheme::HTTPS; config.region = m_ssoRegion; AWS_LOGSTREAM_DEBUG(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Passing config to client for region: " << m_ssoRegion);