Integrating github/staging through commit ef88e6e

This commit is contained in:
alexpete
2021-04-16 12:05:11 -07:00
parent 9c4d8513f1
commit 10faddb113
60 changed files with 2959 additions and 1246 deletions
@@ -12,6 +12,7 @@
#pragma once
#include <Authentication/AuthenticationProviderBus.h>
#include <AzCore/Component/TickBus.h>
namespace AWSClientAuth
{
@@ -28,74 +29,104 @@ namespace AWSClientAuth
OnPasswordGrantMultiFactorConfirmSignInSuccess, OnPasswordGrantMultiFactorConfirmSignInFail,
OnDeviceCodeGrantSignInSuccess, OnDeviceCodeGrantSignInFail,
OnDeviceCodeGrantConfirmSignInSuccess, OnDeviceCodeGrantConfirmSignInFail,
OnRefreshTokensSuccess, OnRefreshTokensFail,
OnSignOut
OnRefreshTokensSuccess, OnRefreshTokensFail
);
void OnPasswordGrantSingleFactorSignInSuccess(const AuthenticationTokens& authenticationToken) override
{
Call(FN_OnPasswordGrantSingleFactorSignInSuccess, authenticationToken);
AZ::TickBus::QueueFunction([authenticationToken, this]()
{
Call(FN_OnPasswordGrantSingleFactorSignInSuccess, authenticationToken);
});
}
void OnPasswordGrantSingleFactorSignInFail(const AZStd::string& error) override
{
Call(FN_OnPasswordGrantSingleFactorSignInFail, error);
AZ::TickBus::QueueFunction([error, this]()
{
Call(FN_OnPasswordGrantSingleFactorSignInFail, error);
});
}
void OnPasswordGrantMultiFactorSignInSuccess() override
{
Call(FN_OnPasswordGrantMultiFactorSignInSuccess);
AZ::TickBus::QueueFunction([this]()
{
Call(FN_OnPasswordGrantMultiFactorSignInSuccess);
});
}
void OnPasswordGrantMultiFactorSignInFail(const AZStd::string& error) override
{
Call(FN_OnPasswordGrantMultiFactorSignInFail, error);
AZ::TickBus::QueueFunction([error, this]()
{
Call(FN_OnPasswordGrantMultiFactorSignInFail, error);
});
}
void OnPasswordGrantMultiFactorConfirmSignInSuccess(const AuthenticationTokens& authenticationToken) override
{
Call(FN_OnPasswordGrantMultiFactorConfirmSignInSuccess, authenticationToken);
AZ::TickBus::QueueFunction([authenticationToken, this]()
{
Call(FN_OnPasswordGrantMultiFactorConfirmSignInSuccess, authenticationToken);
});
}
void OnPasswordGrantMultiFactorConfirmSignInFail(const AZStd::string& error) override
{
Call(FN_OnPasswordGrantMultiFactorConfirmSignInFail, error);
AZ::TickBus::QueueFunction([error, this]()
{
Call(FN_OnPasswordGrantMultiFactorConfirmSignInFail, error);
});
}
void OnDeviceCodeGrantSignInSuccess(
const AZStd::string& userCode, const AZStd::string& verificationUrl, const int codeExpiresInSeconds) override
{
Call(FN_OnDeviceCodeGrantSignInSuccess, userCode, verificationUrl, codeExpiresInSeconds);
AZ::TickBus::QueueFunction([userCode, verificationUrl, codeExpiresInSeconds, this]()
{
Call(FN_OnDeviceCodeGrantSignInSuccess, userCode, verificationUrl, codeExpiresInSeconds);
});
}
void OnDeviceCodeGrantSignInFail(const AZStd::string& error) override
{
Call(FN_OnDeviceCodeGrantSignInFail, error);
AZ::TickBus::QueueFunction([error, this]()
{
Call(FN_OnDeviceCodeGrantSignInFail, error);
});
}
void OnDeviceCodeGrantConfirmSignInSuccess(const AuthenticationTokens& authenticationToken) override
{
Call(FN_OnDeviceCodeGrantConfirmSignInSuccess, authenticationToken);
AZ::TickBus::QueueFunction([authenticationToken, this]()
{
Call(FN_OnDeviceCodeGrantConfirmSignInSuccess, authenticationToken);
});
}
void OnDeviceCodeGrantConfirmSignInFail(const AZStd::string& error) override
{
Call(FN_OnDeviceCodeGrantConfirmSignInFail, error);
AZ::TickBus::QueueFunction([error, this]()
{
Call(FN_OnDeviceCodeGrantConfirmSignInFail, error);
});
}
void OnRefreshTokensSuccess(const AuthenticationTokens& authenticationToken) override
{
Call(FN_OnRefreshTokensSuccess, authenticationToken);
AZ::TickBus::QueueFunction([authenticationToken, this]()
{
Call(FN_OnRefreshTokensSuccess, authenticationToken);
});
}
void OnRefreshTokensFail(const AZStd::string& error) override
{
Call(FN_OnRefreshTokensFail, error);
}
void OnSignOut(const ProviderNameEnum& provideName) override
{
Call(FN_OnSignOut, provideName);
AZ::TickBus::QueueFunction([error, this]()
{
Call(FN_OnRefreshTokensFail, error);
});
}
};
} // namespace AWSClientAuth
@@ -16,6 +16,7 @@
#include <AzCore/std/containers/map.h>
#include <AzCore/std/containers/vector.h>
#include <Authentication/AuthenticationProviderBus.h>
#include <Authentication/AuthenticationProviderScriptCanvasBus.h>
#include <Authentication/AuthenticationProviderInterface.h>
#include <Authentication/AuthenticationTokens.h>
@@ -23,7 +24,8 @@ namespace AWSClientAuth
{
//! Manages various authentication provider implementations and implements AuthenticationProvider Request bus.
class AuthenticationProviderManager
: AuthenticationProviderRequestBus::Handler
: public AuthenticationProviderRequestBus::Handler
, public AuthenticationProviderScriptCanvasRequestBus::Handler
{
public:
AZ_RTTI(AuthenticationProviderManager, "{45813BA5-9A46-4A2A-A923-C79CFBA0E63D}", IAuthenticationProviderRequests);
@@ -43,6 +45,22 @@ namespace AWSClientAuth
bool IsSignedIn(const ProviderNameEnum& providerName) override;
bool SignOut(const ProviderNameEnum& providerName) override;
AuthenticationTokens GetAuthenticationTokens(const ProviderNameEnum& providerName) override;
// AuthenticationProviderScriptCanvasRequest interface
bool Initialize(const AZStd::vector<AZStd::string>& providerNames, const AZStd::string& settingsRegistryPath) override;
void PasswordGrantSingleFactorSignInAsync(
const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password) override;
void PasswordGrantMultiFactorSignInAsync(
const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password) override;
void PasswordGrantMultiFactorConfirmSignInAsync(
const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& confirmationCode) override;
void DeviceCodeGrantSignInAsync(const AZStd::string& providerName) override;
void DeviceCodeGrantConfirmSignInAsync(const AZStd::string& providerName) override;
void RefreshTokensAsync(const AZStd::string& providerName) override;
void GetTokensWithRefreshAsync(const AZStd::string& providerName) override;
bool IsSignedIn(const AZStd::string& providerName) override;
bool SignOut(const AZStd::string& providerName) override;
AuthenticationTokens GetAuthenticationTokens(const AZStd::string& providerName) override;
virtual AZStd::unique_ptr<AuthenticationProviderInterface> CreateAuthenticationProviderObject(const ProviderNameEnum& providerName);
AZStd::map<ProviderNameEnum, AZStd::unique_ptr<AuthenticationProviderInterface>> m_authenticationProvidersMap;
@@ -50,9 +68,9 @@ namespace AWSClientAuth
private:
bool IsProviderInitialized(const ProviderNameEnum& providerName);
void ResetProviders();
ProviderNameEnum GetProviderNameEnum(AZStd::string name);
AZStd::shared_ptr<AZ::SettingsRegistryInterface> m_settingsRegistry;
};
} // namespace AWSClientAuth
@@ -0,0 +1,103 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <Authentication/AuthenticationTokens.h>
namespace AWSClientAuth
{
//! Abstract class for authentication provider script canvas requests.
//! Private class to allow provide names to be string type instead of an enum as behavior context does not work well with enum's.
class IAuthenticationProviderScriptCanvasRequests
{
public:
AZ_TYPE_INFO(IAuthenticationProviderRequests, "{A8FD915F-9FF2-4BA3-8AA0-8CF7A94A323B}");
//! Parse the settings file for required settings for authentication providers. Instantiate and initialize authentication providers
//! @param providerNames List of provider names to instantiate and initialize for Authentication.
//! @param settingsRegistryPath Path for the settings registry file to use to configure providers.
//! @return bool True: if all providers initialized successfully. False: If any provider fails initialization.
virtual bool Initialize(const AZStd::vector<AZStd::string>& providerNames, const AZStd::string& settingsRegistryPath) = 0;
//! Checks if user is signed in.
//! If access tokens are available and not expired.
//! @param providerName Provider to check signed in for
//! @return bool True if valid access token available, else False
virtual bool IsSignedIn(const AZStd::string& providerName) = 0;
//! Get cached tokens from last last successful sign-in for the provider.
//! @param providerName Provider to get authentication tokens
//! @return AuthenticationTokens tokens from successful authentication.
virtual AuthenticationTokens GetAuthenticationTokens(const AZStd::string& providerName) = 0;
// Below methods have corresponding notifications for success and failures.
//! Call sign in endpoint for provider password grant flow.
//! @param providerName Provider to call sign in.
//! @param username Username to use to for sign in.
//! @param password Password to use to for sign in.
virtual void PasswordGrantSingleFactorSignInAsync(const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password) = 0;
//! Call sign in endpoint for provider password grant multi factor authentication flow.
//! @param providerName Provider to call MFA sign in.
//! @param username Username to use for MFA sign in.
//! @param password Password to use for MFA sign in.
virtual void PasswordGrantMultiFactorSignInAsync(const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password) = 0;
//! Call confirm endpoint for provider password grant multi factor authentication flow .
//! @param providerName Provider to call MFA confirm sign in.
//! @param username Username to use for MFA confirm.
//! @param confirmationCode Confirmation code (sent to email/text) to use for MFA confirm.
virtual void PasswordGrantMultiFactorConfirmSignInAsync(const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& confirmationCode) = 0;
//! Call code-pair endpoint for provider device grant flow.
//! @param providerName Provider to call device sign in.
virtual void DeviceCodeGrantSignInAsync(const AZStd::string& providerName) = 0;
//! Call tokens endpoint for provider device grant flow.
//! @param providerName Provider to call device confirm sign in.
virtual void DeviceCodeGrantConfirmSignInAsync(const AZStd::string& providerName) = 0;
//! Call refresh endpoint for provider refresh grant flow.
//! @param providerName Provider to call refresh tokens.
virtual void RefreshTokensAsync(const AZStd::string& providerName) = 0;
//! Call refresh token if token not valid. If token valid, fires corresponding event.
//! @param providerName Provider to get access token for.
//! events: OnRefreshTokensSuccess, OnRefreshTokensFail
virtual void GetTokensWithRefreshAsync(const AZStd::string& providerName) = 0;
//! Signs user out.
//! Clears all cached tokens.
//! @param providerName Provider to sign out.
//! @return bool True: Successfully sign out.
virtual bool SignOut(const AZStd::string& providerName) = 0;
//////////////////////////////////////////////////////////////////////////
};
//! Authentication Request bus for different supported providers.
class AuthenticationProviderScriptCanvasRequests
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
using MutexType = AZ::NullMutex;
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
};
using AuthenticationProviderScriptCanvasRequestBus = AZ::EBus<IAuthenticationProviderScriptCanvasRequests, AuthenticationProviderScriptCanvasRequests>;
} // namespace AWSClientAuth
@@ -15,6 +15,14 @@
namespace AWSClientAuth
{
constexpr char ProvideNameEnumStringNone[] = "None";
constexpr char ProvideNameEnumStringAWSCognitoIDP[] = "AWSCognitoIDP";
constexpr char ProvideNameEnumStringLoginWithAmazon[] = "LoginWithAmazon";
constexpr char ProvideNameEnumStringGoogle[] = "Google";
constexpr char ProvideNameEnumStringApple[] = "Apple";
constexpr char ProvideNameEnumStringFacebook[] = "Facebook";
constexpr char ProvideNameEnumStringTwitch[] = "Twitch";
//! Holds Login with Amazon provider serialized settings
class LWAProviderSetting
{
@@ -12,6 +12,7 @@
#pragma once
#include <Authorization/AWSCognitoAuthorizationBus.h>
#include <AzCore/Component/TickBus.h>
#include <AzCore/RTTI/BehaviorContext.h>
namespace AWSClientAuth
@@ -28,12 +29,18 @@ namespace AWSClientAuth
void OnRequestAWSCredentialsSuccess(const ClientAuthAWSCredentials& awsCredentials) override
{
Call(FN_OnRequestAWSCredentialsSuccess, awsCredentials);
AZ::TickBus::QueueFunction([awsCredentials, this]()
{
Call(FN_OnRequestAWSCredentialsSuccess, awsCredentials);
});
}
void OnRequestAWSCredentialsFail(const AZStd::string& error) override
{
Call(FN_OnRequestAWSCredentialsFail, error);
AZ::TickBus::QueueFunction([error, this]()
{
Call(FN_OnRequestAWSCredentialsFail, error);
});
}
};
} // namespace AWSClientAuth
@@ -12,6 +12,7 @@
#pragma once
#include <UserManagement/AWSCognitoUserManagementBus.h>
#include <AzCore/Component/TickBus.h>
namespace AWSClientAuth
{
@@ -32,62 +33,86 @@ namespace AWSClientAuth
void OnEmailSignUpSuccess(const AZStd::string& uuid) override
{
Call(FN_OnEmailSignUpSuccess, uuid);
AZ::TickBus::QueueFunction([uuid, this]() {
Call(FN_OnEmailSignUpSuccess, uuid);
});
}
void OnEmailSignUpFail(const AZStd::string& error) override
{
Call(FN_OnEmailSignUpFail, error);
AZ::TickBus::QueueFunction([error, this]() {
Call(FN_OnEmailSignUpFail, error);
});
}
void OnPhoneSignUpSuccess(const AZStd::string& uuid) override
{
Call(FN_OnPhoneSignUpSuccess, uuid);
AZ::TickBus::QueueFunction([uuid, this]() {
Call(FN_OnPhoneSignUpSuccess, uuid);
});
}
void OnPhoneSignUpFail(const AZStd::string& error) override
{
Call(FN_OnPhoneSignUpFail, error);
AZ::TickBus::QueueFunction([error, this]() {
Call(FN_OnPhoneSignUpFail, error);
});
}
void OnConfirmSignUpSuccess() override
{
Call(FN_OnConfirmSignUpSuccess);
AZ::TickBus::QueueFunction([this]() {
Call(FN_OnConfirmSignUpSuccess);
});
}
void OnConfirmSignUpFail(const AZStd::string& error) override
{
Call(FN_OnConfirmSignUpFail, error);
AZ::TickBus::QueueFunction([error, this]() {
Call(FN_OnConfirmSignUpFail, error);
});
}
void OnForgotPasswordSuccess() override
{
Call(FN_OnForgotPasswordSuccess);
AZ::TickBus::QueueFunction([this]() {
Call(FN_OnForgotPasswordSuccess);
});
}
void OnForgotPasswordFail(const AZStd::string& error) override
{
Call(FN_OnForgotPasswordFail, error);
AZ::TickBus::QueueFunction([error, this]() {
Call(FN_OnForgotPasswordFail, error);
});
}
void OnConfirmForgotPasswordSuccess() override
{
Call(FN_OnConfirmForgotPasswordSuccess);
AZ::TickBus::QueueFunction([this]() {
Call(FN_OnConfirmForgotPasswordSuccess);
});
}
void OnConfirmForgotPasswordFail(const AZStd::string& error) override
{
Call(FN_OnConfirmForgotPasswordFail, error);
AZ::TickBus::QueueFunction([error, this]() {
Call(FN_OnConfirmForgotPasswordFail, error);
});
}
void OnEnableMFASuccess() override
{
Call(FN_OnEnableMFASuccess);
AZ::TickBus::QueueFunction([this]() {
Call(FN_OnEnableMFASuccess);
});
}
void OnEnableMFAFail(const AZStd::string& error) override
{
Call(FN_OnEnableMFAFail, error);
AZ::TickBus::QueueFunction([error, this]() {
Call(FN_OnEnableMFAFail, error);
});
}
};
} // namespace AWSClientAuth
@@ -16,7 +16,7 @@
namespace AWSClientAuth
{
//@ Abstract class for authentication provider requests.
//! Abstract class for authentication provider requests.
class IAuthenticationProviderRequests
{
public:
@@ -35,32 +35,40 @@ namespace AWSClientAuth
virtual bool IsSignedIn(const ProviderNameEnum& providerName) = 0;
//! Get cached tokens from last last successful sign-in for the provider.
//! @param providerName Provider to get authentication tokens.
//! @return AuthenticationTokens tokens from successful authentication.
virtual AuthenticationTokens GetAuthenticationTokens(const ProviderNameEnum& providerName) = 0;
// Below methods have corresponding notifications for success and failures.
//! Call sign in endpoint for provider password grant flow.
//! @param providerName Provider to call sign in.
//! @param username Username to use to for sign in.
//! @param password Password to use to for sign in.
virtual void PasswordGrantSingleFactorSignInAsync(const ProviderNameEnum& providerName, const AZStd::string& username, const AZStd::string& password) = 0;
//! Call sign in endpoint for provider password grant multi factor authentication flow.
//! @param providerName Provider to call MFA sign in.
//! @param username Username to use for MFA sign in.
//! @param password Password to use for MFA sign in.
virtual void PasswordGrantMultiFactorSignInAsync(const ProviderNameEnum& providerName, const AZStd::string& username, const AZStd::string& password) = 0;
//! Call confirm endpoint for provider password grant multi factor authentication flow .
//! @param providerName Provider to call MFA confirm sign in.
//! @param username Username to use for MFA confirm.
//! @param confirmationCode Confirmation code (sent to email/text) to use for MFA confirm.
virtual void PasswordGrantMultiFactorConfirmSignInAsync(const ProviderNameEnum& providerName, const AZStd::string& username, const AZStd::string& confirmationCode) = 0;
//! Call code-pair endpoint for provider device grant flow.
//! @param providerName Provider to call device sign in.
virtual void DeviceCodeGrantSignInAsync(const ProviderNameEnum& providerName) = 0;
//! Call tokens endpoint for provider device grant flow.
//! @param providerName Provider to call device confirm sign in.
virtual void DeviceCodeGrantConfirmSignInAsync(const ProviderNameEnum& providerName) = 0;
//! Call refresh endpoint for provider refresh grant flow.
//! @param providerName Provider to call refresh tokens.
virtual void RefreshTokensAsync(const ProviderNameEnum& providerName) = 0;
//! Call refresh token if token not valid. If token valid, fires corresponding event.
@@ -11,20 +11,15 @@
*/
#pragma once
#include <AzCore/Preprocessor/Enum.h>
#include <AzCore/std/string/string.h>
#include <AzCore/std/chrono/clocks.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
namespace AWSClientAuth
{
enum class ProviderNameEnum
{
None,
AWSCognitoIDP,
LoginWithAmazon,
Google,
Apple,
Facebook
};
AZ_ENUM_CLASS(ProviderNameEnum, None, AWSCognitoIDP, LoginWithAmazon, Twitch, Google, Apple, Facebook);
//! Used to share authentication tokens to caller and to AWSCognitoAuthorizationController.
class AuthenticationTokens
@@ -55,6 +50,8 @@ namespace AWSClientAuth
//! @return Expiration time in seconds.
int GetTokensExpireTimeSeconds() const;
static void Reflect(AZ::ReflectContext* context);
private:
int m_tokensExpireTimeSeconds = 0;
AZStd::string m_accessToken;
@@ -12,7 +12,7 @@
#pragma once
#include <AzCore/RTTI/TypeInfo.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/std/string/string.h>
#include <aws/core/auth/AWSCredentialsProvider.h>
@@ -24,6 +24,14 @@ namespace AWSClientAuth
{
public:
AZ_TYPE_INFO(ClientAuthAWSCredentials, "{02FB32C4-B94E-4084-9049-3DF32F87BD76}");
ClientAuthAWSCredentials() = default;
ClientAuthAWSCredentials(const ClientAuthAWSCredentials& other)
: m_accessKeyId(other.m_accessKeyId)
, m_secretKey(other.m_secretKey)
, m_sessionToken(other.m_sessionToken)
{
}
ClientAuthAWSCredentials(const AZStd::string& accessKeyId, const AZStd::string& secretKey, const AZStd::string& sessionToken)
{
@@ -50,6 +58,32 @@ namespace AWSClientAuth
return m_sessionToken;
}
static void Reflect(AZ::ReflectContext* context)
{
auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<ClientAuthAWSCredentials>()
->Field("AWSAccessKeyId", &ClientAuthAWSCredentials::m_accessKeyId)
->Field("AWSSecretKey", &ClientAuthAWSCredentials::m_secretKey)
->Field("AWSSessionToken", &ClientAuthAWSCredentials::m_sessionToken);
}
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
if (behaviorContext)
{
behaviorContext->Class<ClientAuthAWSCredentials>()
->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 ClientAuthAWSCredentials&>()
->Property("AWSAccessKeyId", BehaviorValueGetter(&ClientAuthAWSCredentials::m_accessKeyId), BehaviorValueSetter(&ClientAuthAWSCredentials::m_accessKeyId))
->Property("AWSSecretKey", BehaviorValueGetter(&ClientAuthAWSCredentials::m_secretKey), BehaviorValueSetter(&ClientAuthAWSCredentials::m_secretKey))
->Property("AWSSessionToken", BehaviorValueGetter(&ClientAuthAWSCredentials::m_sessionToken), BehaviorValueSetter(&ClientAuthAWSCredentials::m_sessionToken));
}
}
private:
AZStd::string m_accessKeyId;
AZStd::string m_secretKey;
@@ -22,11 +22,12 @@ namespace AWSClientAuth
public:
AZ_TYPE_INFO(IAWSCognitoUserManagementRequests, "{A4C90F21-7056-4827-8C6B-401E6945697D}");
//! Initialize Cognito User pool.
//! Initialize Cognito User pool using settings from resource mappings.
//! @param settingsRegistryPath settingsRegistryPath Path for the settings registry file to use.
virtual bool Initialize() = 0;
// Requests interface
//! Cognito user pool email sign up start.
//! @param username User name to use for sign up.
//! @param password Password to use for sign up.
@@ -59,7 +60,7 @@ namespace AWSClientAuth
virtual void EnableMFAAsync(const AZStd::string& accessToken) = 0;
};
//! Manages various authentication provider implementations and implements AuthenticationProvider Request bus.
//! Implements AWS Cognito user pool user management requests.
class AWSCognitoUserManagementRequests
: public AZ::EBusTraits
{
@@ -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(
@@ -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();
}
@@ -0,0 +1,55 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AWSClientAuthGemMock.h>
#include <Authentication/AuthenticationProviderManager.h>
namespace AWSClientAuthUnitTest
{
class AuthenticationProviderManagerLocalMock
: public AWSClientAuth::AuthenticationProviderManager
{
public:
using AWSClientAuth::AuthenticationProviderManager::DeviceCodeGrantConfirmSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::DeviceCodeGrantSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::GetAuthenticationTokens;
using AWSClientAuth::AuthenticationProviderManager::GetTokensWithRefreshAsync;
using AWSClientAuth::AuthenticationProviderManager::Initialize;
using AWSClientAuth::AuthenticationProviderManager::IsSignedIn;
using AWSClientAuth::AuthenticationProviderManager::m_authenticationProvidersMap;
using AWSClientAuth::AuthenticationProviderManager::PasswordGrantMultiFactorConfirmSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::PasswordGrantMultiFactorSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::PasswordGrantSingleFactorSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::RefreshTokensAsync;
using AWSClientAuth::AuthenticationProviderManager::SignOut;
AZStd::unique_ptr<AWSClientAuth::AuthenticationProviderInterface> CreateAuthenticationProviderObjectMock(
const AWSClientAuth::ProviderNameEnum& providerName)
{
auto providerObject = AWSClientAuth::AuthenticationProviderManager::CreateAuthenticationProviderObject(providerName);
providerObject.reset();
return AZStd::make_unique<testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>>();
}
AuthenticationProviderManagerLocalMock()
{
ON_CALL(*this, CreateAuthenticationProviderObject(testing::_))
.WillByDefault(testing::Invoke(this, &AuthenticationProviderManagerLocalMock::CreateAuthenticationProviderObjectMock));
}
MOCK_METHOD1(
CreateAuthenticationProviderObject,
AZStd::unique_ptr<AWSClientAuth::AuthenticationProviderInterface>(const AWSClientAuth::ProviderNameEnum&));
};
} // namespace AWSClientAuthUnitTest
@@ -0,0 +1,261 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzCore/std/smart_ptr/unique_ptr.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzCore/std/utils.h>
#include <Authentication/AuthenticationProviderManager.h>
#include <Authentication/AWSCognitoAuthenticationProvider.h>
#include <Authentication/LWAAuthenticationProvider.h>
#include <Authentication/AuthenticationTokens.h>
#include <Authentication/AuthenticationProviderTypes.h>
#include <AWSClientAuthGemMock.h>
#include <Authentication/AuthenticationProviderManagerMock.h>
class AuthenticationProviderManagerScriptCanvasTest
: public AWSClientAuthUnitTest::AWSClientAuthGemAllocatorFixture
{
protected:
void SetUp() override
{
AWSClientAuthUnitTest::AWSClientAuthGemAllocatorFixture::SetUp();
AWSClientAuth::LWAProviderSetting::Reflect(*m_serializeContext);
AWSClientAuth::GoogleProviderSetting::Reflect(*m_serializeContext);
m_settingspath = AZStd::string::format("%s/%s/authenticationProvider.setreg",
m_testFolder->c_str(), AZ::SettingsRegistryInterface::RegistryFolder);
CreateTestFile("authenticationProvider.setreg"
, R"({
"AWS":
{
"LoginWithAmazon":
{
"AppClientId": "TestLWAClientId",
"GrantType": "device_code",
"Scope": "profile",
"ResponseType": "device_code",
"OAuthCodeURL": "https://api.amazon.com/auth/o2/create/codepair",
"OAuthTokensURL": "https://oauth2.googleapis.com/token"
},
"Google":
{
"AppClientId": "TestGoogleClientId",
"ClientSecret": "123",
"GrantType": "urn:ietf:params:oauth:grant-type:device_code",
"Scope": "profile",
"OAuthCodeURL": "https://oauth2.googleapis.com/device/code",
"OAuthTokensURL": "https://oauth2.googleapis.com/token"
}
}
})");
m_mockController = AZStd::make_unique<testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderManagerLocalMock>>();
}
void TearDown() override
{
m_mockController.reset();
AWSClientAuthUnitTest::AWSClientAuthGemAllocatorFixture::TearDown();
}
public:
AZStd::unique_ptr<testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderManagerLocalMock>> m_mockController;
AZStd::string m_settingspath;
AZStd::vector<AZStd::string> m_enabledProviderNames { AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP,
AWSClientAuth::ProvideNameEnumStringLoginWithAmazon, AWSClientAuth::ProvideNameEnumStringGoogle};
};
TEST_F(AuthenticationProviderManagerScriptCanvasTest, Initialize_Success)
{
ASSERT_TRUE(m_mockController->Initialize(m_enabledProviderNames, m_settingspath));
ASSERT_TRUE(m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP] != nullptr);
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, PasswordGrantSingleFactorSignInAsync_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock> *cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
EXPECT_CALL(*cognitoProviderMock, PasswordGrantSingleFactorSignInAsync(testing::_, testing::_)).Times(1);
m_mockController->PasswordGrantSingleFactorSignInAsync(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP, AWSClientAuthUnitTest::TEST_USERNAME, AWSClientAuthUnitTest::TEST_PASSWORD);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, PasswordGrantSingleFactorSignInAsync_Fail_NonConfiguredProviderError)
{
AZ_TEST_START_TRACE_SUPPRESSION;
m_mockController->PasswordGrantSingleFactorSignInAsync(AWSClientAuth::ProvideNameEnumStringApple, AWSClientAuthUnitTest::TEST_USERNAME, AWSClientAuthUnitTest::TEST_PASSWORD);
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, PasswordGrantMultiFactorSignInAsync_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* lwaProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::LoginWithAmazon].get();
EXPECT_CALL(*cognitoProviderMock, PasswordGrantMultiFactorSignInAsync(testing::_, testing::_)).Times(1);
m_mockController->PasswordGrantMultiFactorSignInAsync(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP, AWSClientAuthUnitTest::TEST_USERNAME, AWSClientAuthUnitTest::TEST_PASSWORD);
EXPECT_CALL(*lwaProviderMock, PasswordGrantMultiFactorSignInAsync(testing::_, testing::_)).Times(1);
m_mockController->PasswordGrantMultiFactorSignInAsync(AWSClientAuth::ProvideNameEnumStringLoginWithAmazon, AWSClientAuthUnitTest::TEST_USERNAME, AWSClientAuthUnitTest::TEST_PASSWORD);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, PasswordGrantMultiFactorConfirmSignInAsync_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock> *cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock> *lwaProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::LoginWithAmazon].get();
EXPECT_CALL(*cognitoProviderMock, PasswordGrantMultiFactorConfirmSignInAsync(testing::_, testing::_)).Times(1);
m_mockController->PasswordGrantMultiFactorConfirmSignInAsync(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP, AWSClientAuthUnitTest::TEST_USERNAME, AWSClientAuthUnitTest::TEST_PASSWORD);
EXPECT_CALL(*lwaProviderMock, PasswordGrantMultiFactorConfirmSignInAsync(testing::_, testing::_)).Times(1);
m_mockController->PasswordGrantMultiFactorConfirmSignInAsync(AWSClientAuth::ProvideNameEnumStringLoginWithAmazon, AWSClientAuthUnitTest::TEST_USERNAME, AWSClientAuthUnitTest::TEST_PASSWORD);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, DeviceCodeGrantSignInAsync_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* lwaProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::LoginWithAmazon].get();
EXPECT_CALL(*cognitoProviderMock, DeviceCodeGrantSignInAsync()).Times(1);
m_mockController->DeviceCodeGrantSignInAsync(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP);
EXPECT_CALL(*lwaProviderMock, DeviceCodeGrantSignInAsync()).Times(1);
m_mockController->DeviceCodeGrantSignInAsync(AWSClientAuth::ProvideNameEnumStringLoginWithAmazon);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, DeviceCodeGrantConfirmSignInAsync_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* lwaProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::LoginWithAmazon].get();
EXPECT_CALL(*cognitoProviderMock, DeviceCodeGrantConfirmSignInAsync()).Times(1);
m_mockController->DeviceCodeGrantConfirmSignInAsync(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP);
EXPECT_CALL(*lwaProviderMock, DeviceCodeGrantConfirmSignInAsync()).Times(1);
m_mockController->DeviceCodeGrantConfirmSignInAsync(AWSClientAuth::ProvideNameEnumStringLoginWithAmazon);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, RefreshTokenAsync_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock> *cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock> *lwaProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::LoginWithAmazon].get();
EXPECT_CALL(*cognitoProviderMock, RefreshTokensAsync()).Times(1);
m_mockController->RefreshTokensAsync(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP);
EXPECT_CALL(*lwaProviderMock, RefreshTokensAsync()).Times(1);
m_mockController->RefreshTokensAsync(AWSClientAuth::ProvideNameEnumStringLoginWithAmazon);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, GetTokensWithRefreshAsync_ValidToken_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
AWSClientAuth::AuthenticationTokens tokens(
AWSClientAuthUnitTest::TEST_TOKEN, AWSClientAuthUnitTest::TEST_TOKEN, AWSClientAuthUnitTest::TEST_TOKEN,
AWSClientAuth::ProviderNameEnum::AWSCognitoIDP, 600);
EXPECT_CALL(*cognitoProviderMock, GetAuthenticationTokens()).Times(1).WillOnce(testing::Return(tokens));
EXPECT_CALL(*cognitoProviderMock, RefreshTokensAsync()).Times(0);
EXPECT_CALL(m_authenticationProviderNotificationsBusMock, OnRefreshTokensSuccess(testing::_)).Times(1);
m_mockController->GetTokensWithRefreshAsync(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, GetTokensWithRefreshAsync_InvalidToken_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
AWSClientAuth::AuthenticationTokens tokens;
EXPECT_CALL(*cognitoProviderMock, GetAuthenticationTokens()).Times(1).WillOnce(testing::Return(tokens));
EXPECT_CALL(*cognitoProviderMock, RefreshTokensAsync()).Times(1);
m_mockController->GetTokensWithRefreshAsync(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, GetTokensWithRefreshAsync_NotInitializedProvider_Fail)
{
AZ_TEST_START_TRACE_SUPPRESSION;
EXPECT_CALL(m_authenticationProviderNotificationsBusMock, OnRefreshTokensSuccess(testing::_)).Times(0);
EXPECT_CALL(m_authenticationProviderNotificationsBusMock, OnRefreshTokensFail(testing::_)).Times(1);
m_mockController->GetTokensWithRefreshAsync(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP);
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, GetTokens_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
AWSClientAuth::AuthenticationTokens tokens(
AWSClientAuthUnitTest::TEST_TOKEN, AWSClientAuthUnitTest::TEST_TOKEN, AWSClientAuthUnitTest::TEST_TOKEN,
AWSClientAuth::ProviderNameEnum::AWSCognitoIDP, 60);
EXPECT_CALL(*cognitoProviderMock, GetAuthenticationTokens()).Times(1).WillOnce(testing::Return(tokens));
m_mockController->GetAuthenticationTokens(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, IsSignedIn_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* cognitoProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::AWSCognitoIDP].get();
AWSClientAuth::AuthenticationTokens tokens(
AWSClientAuthUnitTest::TEST_TOKEN, AWSClientAuthUnitTest::TEST_TOKEN, AWSClientAuthUnitTest::TEST_TOKEN,
AWSClientAuth::ProviderNameEnum::AWSCognitoIDP, 60);
EXPECT_CALL(*cognitoProviderMock, GetAuthenticationTokens()).Times(1).WillOnce(testing::Return(tokens));
m_mockController->IsSignedIn(AWSClientAuth::ProvideNameEnumStringAWSCognitoIDP);
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, SignOut_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>* googleProviderMock = (testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>*)m_mockController->m_authenticationProvidersMap[AWSClientAuth::ProviderNameEnum::Google].get();
EXPECT_CALL(*googleProviderMock, SignOut()).Times(1);
EXPECT_CALL(m_authenticationProviderNotificationsBusMock, OnSignOut(testing::_)).Times(1);
m_mockController->SignOut(AWSClientAuth::ProvideNameEnumStringGoogle);
googleProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerScriptCanvasTest, Initialize_Fail_InvalidPath)
{
AZ_TEST_START_TRACE_SUPPRESSION;
ASSERT_FALSE(m_mockController->Initialize(m_enabledProviderNames, ""));
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
}
@@ -10,8 +10,6 @@
*
*/
#include <AzTest/AzTest.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/std/smart_ptr/unique_ptr.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzCore/std/utils.h>
@@ -20,42 +18,7 @@
#include <Authentication/LWAAuthenticationProvider.h>
#include <Authentication/AuthenticationTokens.h>
#include <AWSClientAuthGemMock.h>
namespace AWSClientAuthUnitTest
{
class AuthenticationProviderManagerLocalMock
: public AWSClientAuth::AuthenticationProviderManager
{
public:
using AWSClientAuth::AuthenticationProviderManager::m_authenticationProvidersMap;
using AWSClientAuth::AuthenticationProviderManager::Initialize;
using AWSClientAuth::AuthenticationProviderManager::PasswordGrantSingleFactorSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::PasswordGrantMultiFactorSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::PasswordGrantMultiFactorConfirmSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::DeviceCodeGrantSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::DeviceCodeGrantConfirmSignInAsync;
using AWSClientAuth::AuthenticationProviderManager::RefreshTokensAsync;
using AWSClientAuth::AuthenticationProviderManager::GetTokensWithRefreshAsync;
using AWSClientAuth::AuthenticationProviderManager::GetAuthenticationTokens;
using AWSClientAuth::AuthenticationProviderManager::SignOut;
using AWSClientAuth::AuthenticationProviderManager::IsSignedIn;
AZStd::unique_ptr<AWSClientAuth::AuthenticationProviderInterface> CreateAuthenticationProviderObjectMock(const AWSClientAuth::ProviderNameEnum& providerName)
{
auto providerObject = AWSClientAuth::AuthenticationProviderManager::CreateAuthenticationProviderObject(providerName);
providerObject.reset();
return AZStd::make_unique<testing::NiceMock<AWSClientAuthUnitTest::AuthenticationProviderMock>>();
}
AuthenticationProviderManagerLocalMock()
{
ON_CALL(*this, CreateAuthenticationProviderObject(testing::_)).WillByDefault(
testing::Invoke(this, &AuthenticationProviderManagerLocalMock::CreateAuthenticationProviderObjectMock));
}
MOCK_METHOD1(CreateAuthenticationProviderObject, AZStd::unique_ptr<AWSClientAuth::AuthenticationProviderInterface>(const AWSClientAuth::ProviderNameEnum&));
};
}
#include <Authentication/AuthenticationProviderManagerMock.h>
class AuthenticationProviderManagerTest
@@ -239,6 +202,15 @@ TEST_F(AuthenticationProviderManagerTest, GetTokensWithRefreshAsync_InvalidToken
cognitoProviderMock = nullptr;
}
TEST_F(AuthenticationProviderManagerTest, GetTokensWithRefreshAsync_NotInitializedProvider_Fail)
{
AZ_TEST_START_TRACE_SUPPRESSION;
EXPECT_CALL(m_authenticationProviderNotificationsBusMock, OnRefreshTokensSuccess(testing::_)).Times(0);
EXPECT_CALL(m_authenticationProviderNotificationsBusMock, OnRefreshTokensFail(testing::_)).Times(1);
m_mockController->GetTokensWithRefreshAsync(AWSClientAuth::ProviderNameEnum::AWSCognitoIDP);
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
}
TEST_F(AuthenticationProviderManagerTest, GetTokens_Success)
{
m_mockController->Initialize(m_enabledProviderNames, m_settingspath);
@@ -20,6 +20,7 @@ set(FILES
Include/Private/AWSClientAuthBus.h
Include/Private/AWSClientAuthResourceMappingConstants.h
Include/Private/Authentication/AuthenticationProviderTypes.h
Include/Private/Authentication/AuthenticationProviderScriptCanvasBus.h
Include/Private/Authentication/AuthenticationProviderManager.h
Include/Private/Authentication/AuthenticationNotificationBusBehaviorHandler.h
@@ -14,7 +14,9 @@ set(FILES
Tests/AWSClientAuthGemTest.cpp
Tests/AWSClientAuthSystemComponentTest.cpp
Tests/Authentication/AuthenticationProviderManagerMock.h
Tests/Authentication/AuthenticationProviderManagerTest.cpp
Tests/Authentication/AuthenticationProviderManagerScriptCanvasBusTest.cpp
Tests/Authentication/AWSCognitoAuthenticationProviderTest.cpp
Tests/Authentication/LWAAuthenticationProviderTest.cpp
Tests/Authentication/GoogleAuthenticationProviderTest.cpp