Integrating github/staging through commit ef88e6e
This commit is contained in:
@@ -22,6 +22,11 @@
|
||||
#include <aws/cognito-identity/CognitoIdentityClient.h>
|
||||
#include <aws/cognito-idp/CognitoIdentityProviderClient.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
AZ_TYPE_INFO_SPECIALIZE(AWSClientAuth::ProviderNameEnum, "{FB34B23A-B249-47A2-B1F1-C05284B50CCC}");
|
||||
}
|
||||
|
||||
namespace AWSClientAuth
|
||||
{
|
||||
constexpr char SerializeComponentName[] = "AWSClientAuth";
|
||||
@@ -44,20 +49,35 @@ namespace AWSClientAuth
|
||||
AWSClientAuth::GoogleProviderSetting::Reflect(*serialize);
|
||||
}
|
||||
|
||||
AWSClientAuth::AuthenticationTokens::Reflect(context);
|
||||
AWSClientAuth::ClientAuthAWSCredentials::Reflect(context);
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->EBus<AuthenticationProviderRequestBus>("AuthenticationProviderRequestBus")
|
||||
behaviorContext->Enum<(int)ProviderNameEnum::None>("ProviderNameEnum_None")
|
||||
->Enum<(int)ProviderNameEnum::AWSCognitoIDP>("ProviderNameEnum_AWSCognitoIDP")
|
||||
->Enum<(int)ProviderNameEnum::LoginWithAmazon>("ProviderNameEnum_LoginWithAmazon")
|
||||
->Enum<(int)ProviderNameEnum::Google>("ProviderNameEnum_Google");
|
||||
|
||||
behaviorContext->EBus<AuthenticationProviderScriptCanvasRequestBus>("AuthenticationProviderRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, SerializeComponentName)
|
||||
->Event("Initialize", &AuthenticationProviderRequestBus::Events::Initialize)
|
||||
->Event("IsSignedIn", &AuthenticationProviderRequestBus::Events::IsSignedIn)
|
||||
->Event("GetAuthenticationTokens", &AuthenticationProviderRequestBus::Events::GetAuthenticationTokens)
|
||||
->Event("Initialize", &AuthenticationProviderScriptCanvasRequestBus::Events::Initialize)
|
||||
->Event("IsSignedIn", &AuthenticationProviderScriptCanvasRequestBus::Events::IsSignedIn)
|
||||
->Event("GetAuthenticationTokens", &AuthenticationProviderScriptCanvasRequestBus::Events::GetAuthenticationTokens)
|
||||
->Event(
|
||||
"PasswordGrantSingleFactorSignInAsync", &AuthenticationProviderRequestBus::Events::PasswordGrantSingleFactorSignInAsync)
|
||||
->Event("DeviceCodeGrantSignInAsync", &AuthenticationProviderRequestBus::Events::DeviceCodeGrantSignInAsync)
|
||||
->Event("DeviceCodeGrantConfirmSignInAsync", &AuthenticationProviderRequestBus::Events::DeviceCodeGrantConfirmSignInAsync)
|
||||
->Event("RefreshTokensAsync", &AuthenticationProviderRequestBus::Events::RefreshTokensAsync)
|
||||
->Event("GetTokensWithRefreshAsync", &AuthenticationProviderRequestBus::Events::GetTokensWithRefreshAsync)
|
||||
->Event("SignOut", &AuthenticationProviderRequestBus::Events::SignOut);
|
||||
"PasswordGrantSingleFactorSignInAsync",
|
||||
&AuthenticationProviderScriptCanvasRequestBus::Events::PasswordGrantSingleFactorSignInAsync)
|
||||
->Event(
|
||||
"PasswordGrantMultiFactorSignInAsync",
|
||||
&AuthenticationProviderScriptCanvasRequestBus::Events::PasswordGrantMultiFactorSignInAsync)
|
||||
->Event(
|
||||
"PasswordGrantMultiFactorConfirmSignInAsync",
|
||||
&AuthenticationProviderScriptCanvasRequestBus::Events::PasswordGrantMultiFactorConfirmSignInAsync)
|
||||
->Event("DeviceCodeGrantSignInAsync", &AuthenticationProviderScriptCanvasRequestBus::Events::DeviceCodeGrantSignInAsync)
|
||||
->Event("DeviceCodeGrantConfirmSignInAsync", &AuthenticationProviderScriptCanvasRequestBus::Events::DeviceCodeGrantConfirmSignInAsync)
|
||||
->Event("RefreshTokensAsync", &AuthenticationProviderScriptCanvasRequestBus::Events::RefreshTokensAsync)
|
||||
->Event("GetTokensWithRefreshAsync", &AuthenticationProviderScriptCanvasRequestBus::Events::GetTokensWithRefreshAsync)
|
||||
->Event("SignOut", &AuthenticationProviderScriptCanvasRequestBus::Events::SignOut);
|
||||
|
||||
behaviorContext->EBus<AWSCognitoAuthorizationRequestBus>("AWSCognitoAuthorizationRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, SerializeComponentName)
|
||||
@@ -77,11 +97,15 @@ namespace AWSClientAuth
|
||||
->Event("ConfirmForgotPasswordAsync", &AWSCognitoUserManagementRequestBus::Events::ConfirmForgotPasswordAsync)
|
||||
->Event("EnableMFAAsync", &AWSCognitoUserManagementRequestBus::Events::EnableMFAAsync);
|
||||
|
||||
|
||||
behaviorContext->EBus<AuthenticationProviderNotificationBus>("AuthenticationProviderNotificationBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, SerializeComponentName)
|
||||
->Handler<AuthenticationNotificationBusBehaviorHandler>();
|
||||
behaviorContext->EBus<AWSCognitoUserManagementNotificationBus>("AWSCognitoUserManagementNotificationBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, SerializeComponentName)
|
||||
->Handler<UserManagementNotificationBusBehaviorHandler>();
|
||||
behaviorContext->EBus<AWSCognitoAuthorizationNotificationBus>("AWSCognitoAuthorizationNotificationBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, SerializeComponentName)
|
||||
->Handler<AWSCognitoAuthorizationNotificationBusBehaviorHandler>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace AWSClientAuth
|
||||
AZ_UNUSED(settingsRegistry);
|
||||
AWSCore::AWSResourceMappingRequestBus::BroadcastResult(
|
||||
m_cognitoAppClientId, &AWSCore::AWSResourceMappingRequests::GetResourceNameId, CognitoAppClientIdResourceMappingKey);
|
||||
AZ_Warning("AWSCognitoAuthenticationProvider", m_cognitoAppClientId.empty(), "Missing Cognito App Client Id from resource mappings. Calls to Cognito will fail.");
|
||||
AZ_Warning("AWSCognitoAuthenticationProvider", !m_cognitoAppClientId.empty(), "Missing Cognito App Client Id from resource mappings. Calls to Cognito will fail.");
|
||||
return !m_cognitoAppClientId.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzCore/Settings/SettingsRegistryImpl.h>
|
||||
#include <AzCore/IO/FileIO.h>
|
||||
|
||||
#include <Authentication/AuthenticationProviderTypes.h>
|
||||
#include <Authentication/AWSCognitoAuthenticationProvider.h>
|
||||
@@ -25,12 +26,14 @@ namespace AWSClientAuth
|
||||
{
|
||||
AZ::Interface<IAuthenticationProviderRequests>::Register(this);
|
||||
AuthenticationProviderRequestBus::Handler::BusConnect();
|
||||
AuthenticationProviderScriptCanvasRequestBus::Handler::BusConnect();
|
||||
}
|
||||
|
||||
AuthenticationProviderManager::~AuthenticationProviderManager()
|
||||
{
|
||||
ResetProviders();
|
||||
m_settingsRegistry.reset();
|
||||
AuthenticationProviderScriptCanvasRequestBus::Handler::BusDisconnect();
|
||||
AuthenticationProviderRequestBus::Handler::BusDisconnect();
|
||||
AZ::Interface<IAuthenticationProviderRequests>::Unregister(this);
|
||||
}
|
||||
@@ -38,12 +41,19 @@ namespace AWSClientAuth
|
||||
bool AuthenticationProviderManager::Initialize(const AZStd::vector<ProviderNameEnum>& providerNames, const AZStd::string& settingsRegistryPath)
|
||||
{
|
||||
ResetProviders();
|
||||
AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance();
|
||||
AZ_Assert(fileIO, "File IO is not initialized.");
|
||||
|
||||
m_settingsRegistry.reset();
|
||||
m_settingsRegistry = AZStd::make_shared<AZ::SettingsRegistryImpl>();
|
||||
|
||||
if (!m_settingsRegistry->MergeSettingsFile(settingsRegistryPath, AZ::SettingsRegistryInterface::Format::JsonMergePatch))
|
||||
AZStd::array<char, AZ::IO::MaxPathLength> resolvedPath{};
|
||||
AZ::IO::FileIOBase::GetInstance()->ResolvePath(settingsRegistryPath.data(), resolvedPath.data(), resolvedPath.size());
|
||||
|
||||
|
||||
if (!m_settingsRegistry->MergeSettingsFile(resolvedPath.data(), AZ::SettingsRegistryInterface::Format::JsonMergePatch))
|
||||
{
|
||||
AZ_Error("AuthenticationProviderManager", true, "Error merging settings registry for path: %s", settingsRegistryPath.c_str());
|
||||
AZ_Error("AuthenticationProviderManager", true, "Error merging settings registry for path: %s", resolvedPath.data());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -112,6 +122,7 @@ namespace AWSClientAuth
|
||||
{
|
||||
AuthenticationProviderNotificationBus::Broadcast(&AuthenticationProviderNotifications::OnRefreshTokensFail
|
||||
, "Provider is not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
AuthenticationTokens tokens = m_authenticationProvidersMap[providerName]->GetAuthenticationTokens();
|
||||
@@ -181,5 +192,77 @@ namespace AWSClientAuth
|
||||
}
|
||||
}
|
||||
|
||||
ProviderNameEnum AuthenticationProviderManager::GetProviderNameEnum(AZStd::string name)
|
||||
{
|
||||
auto enumValue = ProviderNameEnumNamespace::FromStringToProviderNameEnum(name);
|
||||
if (enumValue.has_value())
|
||||
{
|
||||
return enumValue.value();
|
||||
}
|
||||
AZ_Warning("AuthenticationProviderManager", true, "Incorrect string value for enum: %s", name.c_str());
|
||||
return ProviderNameEnum::None;
|
||||
}
|
||||
|
||||
bool AuthenticationProviderManager::Initialize(
|
||||
const AZStd::vector<AZStd::string>& providerNames, const AZStd::string& settingsRegistryPath)
|
||||
{
|
||||
AZStd::vector<ProviderNameEnum> providerNamesEnum;
|
||||
for (auto name : providerNames)
|
||||
{
|
||||
providerNamesEnum.push_back(GetProviderNameEnum(name));
|
||||
}
|
||||
return Initialize(providerNamesEnum, settingsRegistryPath);
|
||||
}
|
||||
|
||||
void AuthenticationProviderManager::PasswordGrantSingleFactorSignInAsync(const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password)
|
||||
{
|
||||
PasswordGrantSingleFactorSignInAsync(GetProviderNameEnum(providerName), username, password);
|
||||
}
|
||||
|
||||
void AuthenticationProviderManager::PasswordGrantMultiFactorSignInAsync(const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password)
|
||||
{
|
||||
PasswordGrantMultiFactorSignInAsync(GetProviderNameEnum(providerName), username, password);
|
||||
}
|
||||
|
||||
void AuthenticationProviderManager::PasswordGrantMultiFactorConfirmSignInAsync(const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& confirmationCode)
|
||||
{
|
||||
PasswordGrantMultiFactorConfirmSignInAsync(GetProviderNameEnum(providerName), username, confirmationCode);
|
||||
}
|
||||
|
||||
void AuthenticationProviderManager::DeviceCodeGrantSignInAsync(const AZStd::string& providerName)
|
||||
{
|
||||
DeviceCodeGrantSignInAsync(GetProviderNameEnum(providerName));
|
||||
}
|
||||
|
||||
void AuthenticationProviderManager::DeviceCodeGrantConfirmSignInAsync(const AZStd::string& providerName)
|
||||
{
|
||||
DeviceCodeGrantConfirmSignInAsync(GetProviderNameEnum(providerName));
|
||||
}
|
||||
|
||||
void AuthenticationProviderManager::RefreshTokensAsync(const AZStd::string& providerName)
|
||||
{
|
||||
RefreshTokensAsync(GetProviderNameEnum(providerName));
|
||||
}
|
||||
|
||||
void AuthenticationProviderManager::GetTokensWithRefreshAsync(const AZStd::string& providerName)
|
||||
{
|
||||
GetTokensWithRefreshAsync(GetProviderNameEnum(providerName));
|
||||
}
|
||||
|
||||
bool AuthenticationProviderManager::IsSignedIn(const AZStd::string& providerName)
|
||||
{
|
||||
return IsSignedIn(GetProviderNameEnum(providerName));
|
||||
}
|
||||
|
||||
bool AuthenticationProviderManager::SignOut(const AZStd::string& providerName)
|
||||
{
|
||||
return SignOut(GetProviderNameEnum(providerName));
|
||||
}
|
||||
|
||||
AuthenticationTokens AuthenticationProviderManager::GetAuthenticationTokens(const AZStd::string& providerName)
|
||||
{
|
||||
return GetAuthenticationTokens(GetProviderNameEnum(providerName));
|
||||
}
|
||||
|
||||
} // namespace AWSClientAuth
|
||||
|
||||
|
||||
@@ -79,4 +79,30 @@ namespace AWSClientAuth
|
||||
{
|
||||
return m_tokensExpireTimeSeconds;
|
||||
}
|
||||
|
||||
void AuthenticationTokens::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
if (serializeContext)
|
||||
{
|
||||
serializeContext->Class<AuthenticationTokens>()
|
||||
->Field("AccessToken", &AuthenticationTokens::m_accessToken)
|
||||
->Field("OpenIdToken", &AuthenticationTokens::m_openIdToken)
|
||||
->Field("RefreshToken", &AuthenticationTokens::m_refreshToken);
|
||||
}
|
||||
|
||||
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
|
||||
if (behaviorContext)
|
||||
{
|
||||
behaviorContext->Class<AuthenticationTokens>()
|
||||
->Attribute(AZ::Script::Attributes::Category, "AWSClientAuth")
|
||||
->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value)
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
|
||||
->Constructor()
|
||||
->Constructor<const AuthenticationTokens&>()
|
||||
->Property("AccessToken", BehaviorValueGetter(&AuthenticationTokens::m_accessToken), BehaviorValueSetter(&AuthenticationTokens::m_accessToken))
|
||||
->Property("OpenIdToken", BehaviorValueGetter(&AuthenticationTokens::m_openIdToken), BehaviorValueSetter(&AuthenticationTokens::m_accessToken))
|
||||
->Property("RefreshToken", BehaviorValueGetter(&AuthenticationTokens::m_refreshToken), BehaviorValueSetter(&AuthenticationTokens::m_accessToken));
|
||||
}
|
||||
}
|
||||
} // namespace AWSClientAuth
|
||||
|
||||
@@ -71,15 +71,15 @@ namespace AWSClientAuth
|
||||
|
||||
if (m_awsAccountId.empty() || m_cognitoIdentityPoolId.empty())
|
||||
{
|
||||
AZ_Warning("AWSCognitoUserManagementController", m_awsAccountId.empty(), "Missing AWS account id in resource mappings.");
|
||||
AZ_Warning("AWSCognitoUserManagementController", m_cognitoIdentityPoolId.empty(), "Missing Cognito Identity pool id in resource mappings.");
|
||||
AZ_Warning("AWSCognitoAuthorizationController", !m_awsAccountId.empty(), "Missing AWS account id not configured.");
|
||||
AZ_Warning("AWSCognitoAuthorizationController", !m_cognitoIdentityPoolId.empty(), "Missing Cognito Identity pool id in resource mappings.");
|
||||
return false;
|
||||
}
|
||||
|
||||
AZStd::string userPoolId;
|
||||
AWSCore::AWSResourceMappingRequestBus::BroadcastResult(
|
||||
userPoolId, &AWSCore::AWSResourceMappingRequests::GetResourceNameId, CognitoUserPoolIdResourceMappingKey);
|
||||
AZ_Warning("AWSCognitoUserManagementController", userPoolId.empty(), "Missing Cognito USer pool id in resource mappings. Cognito IDP authenticated identities will no work.");
|
||||
AZ_Warning("AWSCognitoAuthorizationController", !userPoolId.empty(), "Missing Cognito User pool id in resource mappings. Cognito IDP authenticated identities will no work.");
|
||||
|
||||
AZStd::string defaultRegion;
|
||||
AWSCore::AWSResourceMappingRequestBus::BroadcastResult(
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ namespace AWSClientAuth
|
||||
AWSCore::AWSResourceMappingRequestBus::BroadcastResult(
|
||||
m_cognitoAppClientId, &AWSCore::AWSResourceMappingRequests::GetResourceNameId, CognitoAppClientIdResourceMappingKey);
|
||||
AZ_Warning(
|
||||
"AWSCognitoUserManagementController", m_cognitoAppClientId.empty(), "Missing Cognito App Client Id from resource mappings. Calls to Cognito will fail.");
|
||||
"AWSCognitoUserManagementController", !m_cognitoAppClientId.empty(), "Missing Cognito App Client Id from resource mappings. Calls to Cognito will fail.");
|
||||
return !m_cognitoAppClientId.empty();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user