Integrating latest from github/staging
Integrating up through commit 5e1bdae
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
#include <UserManagement/UserManagementNotificationBusBehaviorHandler.h>
|
||||
#include <Authorization/AWSCognitoAuthorizationNotificationBusBehaviorHandler.h>
|
||||
#include <Authorization/AWSCognitoAuthorizationController.h>
|
||||
#include <Authorization/AWSCognitoAuthorizationTypes.h>
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <ResourceMapping/AWSResourceMappingBus.h>
|
||||
|
||||
@@ -25,7 +24,7 @@
|
||||
|
||||
namespace AWSClientAuth
|
||||
{
|
||||
constexpr char SERIALIZE_COMPONENT_NAME[] = "AWSClientAuth";
|
||||
constexpr char SerializeComponentName[] = "AWSClientAuth";
|
||||
|
||||
void AWSClientAuthSystemComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
@@ -41,17 +40,14 @@ namespace AWSClientAuth
|
||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true);
|
||||
}
|
||||
AWSClientAuth::AWSCognitoProviderSetting::Reflect(*serialize);
|
||||
AWSClientAuth::LWAProviderSetting::Reflect(*serialize);
|
||||
AWSClientAuth::GoogleProviderSetting::Reflect(*serialize);
|
||||
AWSClientAuth::CognitoAuthorizationSettings::Reflect(*serialize);
|
||||
AWSClientAuth::AWSCognitoUserManagementSetting::Reflect(*serialize);
|
||||
}
|
||||
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->EBus<AuthenticationProviderRequestBus>("AuthenticationProviderRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, SERIALIZE_COMPONENT_NAME)
|
||||
->Attribute(AZ::Script::Attributes::Category, SerializeComponentName)
|
||||
->Event("Initialize", &AuthenticationProviderRequestBus::Events::Initialize)
|
||||
->Event("IsSignedIn", &AuthenticationProviderRequestBus::Events::IsSignedIn)
|
||||
->Event("GetAuthenticationTokens", &AuthenticationProviderRequestBus::Events::GetAuthenticationTokens)
|
||||
@@ -64,7 +60,7 @@ namespace AWSClientAuth
|
||||
->Event("SignOut", &AuthenticationProviderRequestBus::Events::SignOut);
|
||||
|
||||
behaviorContext->EBus<AWSCognitoAuthorizationRequestBus>("AWSCognitoAuthorizationRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, SERIALIZE_COMPONENT_NAME)
|
||||
->Attribute(AZ::Script::Attributes::Category, SerializeComponentName)
|
||||
->Event("Initialize", &AWSCognitoAuthorizationRequestBus::Events::Initialize)
|
||||
->Event("Reset", &AWSCognitoAuthorizationRequestBus::Events::Reset)
|
||||
->Event("GetIdentityId", &AWSCognitoAuthorizationRequestBus::Events::GetIdentityId)
|
||||
@@ -72,7 +68,7 @@ namespace AWSClientAuth
|
||||
->Event("RequestAWSCredentialsAsync", &AWSCognitoAuthorizationRequestBus::Events::RequestAWSCredentialsAsync);
|
||||
|
||||
behaviorContext->EBus<AWSCognitoUserManagementRequestBus>("AWSCognitoUserManagementRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::Category, SERIALIZE_COMPONENT_NAME)
|
||||
->Attribute(AZ::Script::Attributes::Category, SerializeComponentName)
|
||||
->Event("Initialize", &AWSCognitoUserManagementRequestBus::Events::Initialize)
|
||||
->Event("EmailSignUpAsync", &AWSCognitoUserManagementRequestBus::Events::EmailSignUpAsync)
|
||||
->Event("PhoneSignUpAsync", &AWSCognitoUserManagementRequestBus::Events::PhoneSignUpAsync)
|
||||
|
||||
+19
-30
@@ -18,6 +18,8 @@
|
||||
#include <Authentication/AuthenticationProviderBus.h>
|
||||
#include <AWSClientAuthBus.h>
|
||||
#include <AWSCoreBus.h>
|
||||
#include <ResourceMapping/AWSResourceMappingBus.h>
|
||||
#include <AWSClientAuthResourceMappingConstants.h>
|
||||
|
||||
#include <aws/cognito-idp/model/InitiateAuthRequest.h>
|
||||
#include <aws/cognito-idp/model/InitiateAuthResult.h>
|
||||
@@ -28,31 +30,18 @@
|
||||
|
||||
namespace AWSClientAuth
|
||||
{
|
||||
|
||||
constexpr char COGNITO_IDP_SETTINGS_PATH[] = "/AWS/CognitoIDP";
|
||||
constexpr char COGNITO_USERNAME_KEY[] = "USERNAME";
|
||||
constexpr char COGNITO_PASSWORD_KEY[] = "PASSWORD";
|
||||
constexpr char COGNITO_REFRESH_TOKEN_AUTHPARAM_KEY[] = "REFRESH_TOKEN";
|
||||
constexpr char COGNITO_SMS_MFA_CODE_KEY[] = "SMS_MFA_CODE";
|
||||
|
||||
AWSCognitoAuthenticationProvider::AWSCognitoAuthenticationProvider()
|
||||
{
|
||||
m_settings = AZStd::make_unique<AWSCognitoProviderSetting>();
|
||||
}
|
||||
|
||||
AWSCognitoAuthenticationProvider::~AWSCognitoAuthenticationProvider()
|
||||
{
|
||||
m_settings.reset();
|
||||
}
|
||||
constexpr char CognitoUsernameKey[] = "USERNAME";
|
||||
constexpr char CognitoPasswordKey[] = "PASSWORD";
|
||||
constexpr char CognitoRefreshTokenAuthParamKey[] = "REFRESH_TOKEN";
|
||||
constexpr char CognitoSmsMfaCodeKey[] = "SMS_MFA_CODE";
|
||||
|
||||
bool AWSCognitoAuthenticationProvider::Initialize(AZStd::weak_ptr<AZ::SettingsRegistryInterface> settingsRegistry)
|
||||
{
|
||||
if (!settingsRegistry.lock()->GetObject(m_settings.get(), azrtti_typeid(m_settings.get()), COGNITO_IDP_SETTINGS_PATH))
|
||||
{
|
||||
AZ_Warning("AWSCognitoAuthenticationProvider", true, "Failed to get settings object for path %s", COGNITO_IDP_SETTINGS_PATH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
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.");
|
||||
return !m_cognitoAppClientId.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -128,9 +117,9 @@ namespace AWSClientAuth
|
||||
// Set Request parameters for SMS Multi factor authentication.
|
||||
// Note: Email MFA is no longer supported by Cognito, use SMS as MFA
|
||||
Aws::CognitoIdentityProvider::Model::RespondToAuthChallengeRequest respondToAuthChallengeRequest;
|
||||
respondToAuthChallengeRequest.SetClientId(m_settings->m_appClientId.c_str());
|
||||
respondToAuthChallengeRequest.AddChallengeResponses(COGNITO_SMS_MFA_CODE_KEY, confirmationCode.c_str());
|
||||
respondToAuthChallengeRequest.AddChallengeResponses(COGNITO_USERNAME_KEY, username.c_str());
|
||||
respondToAuthChallengeRequest.SetClientId(m_cognitoAppClientId.c_str());
|
||||
respondToAuthChallengeRequest.AddChallengeResponses(CognitoSmsMfaCodeKey, confirmationCode.c_str());
|
||||
respondToAuthChallengeRequest.AddChallengeResponses(CognitoUsernameKey, username.c_str());
|
||||
respondToAuthChallengeRequest.SetChallengeName(Aws::CognitoIdentityProvider::Model::ChallengeNameType::SMS_MFA);
|
||||
respondToAuthChallengeRequest.SetSession(m_session.c_str());
|
||||
|
||||
@@ -177,13 +166,13 @@ namespace AWSClientAuth
|
||||
{
|
||||
// Set Request parameters.
|
||||
Aws::CognitoIdentityProvider::Model::InitiateAuthRequest initiateAuthRequest;
|
||||
initiateAuthRequest.SetClientId(m_settings->m_appClientId.c_str());
|
||||
initiateAuthRequest.SetClientId(m_cognitoAppClientId.c_str());
|
||||
initiateAuthRequest.SetAuthFlow(Aws::CognitoIdentityProvider::Model::AuthFlowType::REFRESH_TOKEN_AUTH);
|
||||
|
||||
// Set username and password for Password grant/ Initiate Auth flow.
|
||||
Aws::Map<Aws::String, Aws::String> authParameters
|
||||
{
|
||||
{COGNITO_REFRESH_TOKEN_AUTHPARAM_KEY, GetAuthenticationTokens().GetRefreshToken().c_str()}
|
||||
{CognitoRefreshTokenAuthParamKey, GetAuthenticationTokens().GetRefreshToken().c_str()}
|
||||
};
|
||||
initiateAuthRequest.SetAuthParameters(authParameters);
|
||||
|
||||
@@ -228,14 +217,14 @@ namespace AWSClientAuth
|
||||
{
|
||||
// Set Request parameters.
|
||||
Aws::CognitoIdentityProvider::Model::InitiateAuthRequest initiateAuthRequest;
|
||||
initiateAuthRequest.SetClientId(m_settings->m_appClientId.c_str());
|
||||
initiateAuthRequest.SetClientId(m_cognitoAppClientId.c_str());
|
||||
initiateAuthRequest.SetAuthFlow(Aws::CognitoIdentityProvider::Model::AuthFlowType::USER_PASSWORD_AUTH);
|
||||
|
||||
// Set username and password for Password grant/ Initiate Auth flow.
|
||||
Aws::Map<Aws::String, Aws::String> authParameters
|
||||
{
|
||||
{COGNITO_USERNAME_KEY, username.c_str()},
|
||||
{COGNITO_PASSWORD_KEY, password.c_str()}
|
||||
{CognitoUsernameKey, username.c_str()},
|
||||
{CognitoPasswordKey, password.c_str()}
|
||||
};
|
||||
initiateAuthRequest.SetAuthParameters(authParameters);
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
namespace AWSClientAuth
|
||||
{
|
||||
|
||||
constexpr char GOOGLE_SETTINGS_PATH[] = "/AWS/Google";
|
||||
constexpr char GOOGLE_VERIFICATION_URL_RESPONSE_KEY[] = "verification_url";
|
||||
constexpr char GoogleSettingsPath[] = "/AWS/Google";
|
||||
constexpr char GoogleVerificationUrlResponseKey[] = "verification_url";
|
||||
|
||||
GoogleAuthenticationProvider::GoogleAuthenticationProvider()
|
||||
{
|
||||
@@ -37,9 +37,9 @@ namespace AWSClientAuth
|
||||
|
||||
bool GoogleAuthenticationProvider::Initialize(AZStd::weak_ptr<AZ::SettingsRegistryInterface> settingsRegistry)
|
||||
{
|
||||
if (!settingsRegistry.lock()->GetObject(m_settings.get(), azrtti_typeid(m_settings.get()), GOOGLE_SETTINGS_PATH))
|
||||
if (!settingsRegistry.lock()->GetObject(m_settings.get(), azrtti_typeid(m_settings.get()), GoogleSettingsPath))
|
||||
{
|
||||
AZ_Warning("AWSCognitoAuthenticationProvider", true, "Failed to get Google settings object for path %s", GOOGLE_SETTINGS_PATH);
|
||||
AZ_Warning("AWSCognitoAuthenticationProvider", true, "Failed to get Google settings object for path %s", GoogleSettingsPath);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -70,13 +70,13 @@ namespace AWSClientAuth
|
||||
// Refer https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes.
|
||||
void GoogleAuthenticationProvider::DeviceCodeGrantSignInAsync()
|
||||
{
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s", OAUTH_CLIENT_ID_BODY_KEY, m_settings->m_appClientId.c_str()
|
||||
, OAUTH_SCOPE_BODY_KEY, OAUTH_SCOPE_BODY_VALUE);
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s", OAuthClientIdBodyKey, m_settings->m_appClientId.c_str()
|
||||
, OAuthScopeBodyKey, OAuthScopeBodyValue);
|
||||
|
||||
// Set headers and body for device sign in http requests.
|
||||
AZStd::map<AZStd::string, AZStd::string> headers;
|
||||
headers[OAUTH_CONTENT_TYPE_HEADER_KEY] = OAUTH_CONTENT_TYPE_HEADER_VALUE;
|
||||
headers[OAUTH_CONTENT_LENGTH_HEADER_KEY] = AZStd::to_string(body.length());
|
||||
headers[OAuthContentTypeHeaderKey] = OAuthContentTypeHeaderValue;
|
||||
headers[OAuthContentLengthHeaderKey] = AZStd::to_string(body.length());
|
||||
|
||||
HttpRequestor::HttpRequestorRequestBus::Broadcast(&HttpRequestor::HttpRequestorRequests::AddRequestWithHeadersAndBody, m_settings->m_oAuthCodeURL
|
||||
, Aws::Http::HttpMethod::HTTP_POST, headers, body
|
||||
@@ -84,15 +84,15 @@ namespace AWSClientAuth
|
||||
{
|
||||
if (responseCode == Aws::Http::HttpResponseCode::OK)
|
||||
{
|
||||
m_cachedDeviceCode = jsonView.GetString(OAUTH_DEVICE_CODE_BODY_KEY).c_str();
|
||||
m_cachedDeviceCode = jsonView.GetString(OAuthDeviceCodeBodyKey).c_str();
|
||||
AuthenticationProviderNotificationBus::Broadcast(&AuthenticationProviderNotifications::OnDeviceCodeGrantSignInSuccess
|
||||
, jsonView.GetString(OAUTH_USER_CODE_RESPONSE_KEY).c_str(), jsonView.GetString(GOOGLE_VERIFICATION_URL_RESPONSE_KEY).c_str()
|
||||
, jsonView.GetInteger(OAUTH_EXPIRES_IN_RESPONSE_KEY));
|
||||
, jsonView.GetString(OAuthUserCodeResponseKey).c_str(), jsonView.GetString(GoogleVerificationUrlResponseKey).c_str()
|
||||
, jsonView.GetInteger(OAuthExpiresInResponseKey));
|
||||
}
|
||||
else
|
||||
{
|
||||
AuthenticationProviderNotificationBus::Broadcast(&AuthenticationProviderNotifications::OnDeviceCodeGrantSignInFail
|
||||
, jsonView.GetString(OAUTH_ERROR_RESPONSE_KEY).c_str());
|
||||
, jsonView.GetString(OAuthErrorResponseKey).c_str());
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -105,12 +105,12 @@ namespace AWSClientAuth
|
||||
{
|
||||
// Set headers and body for device confirm sign in http requests.
|
||||
AZStd::map<AZStd::string, AZStd::string> headers;
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s&%s=%s", OAUTH_CLIENT_ID_BODY_KEY, m_settings->m_appClientId.c_str()
|
||||
, OAUTH_CLIENT_SECRET_BODY_KEY, m_settings->m_clientSecret.c_str(), OAUTH_DEVICE_CODE_BODY_KEY, m_cachedDeviceCode.c_str()
|
||||
, OAUTH_GRANT_TYPE_BODY_KEY, m_settings->m_grantType.c_str());
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s&%s=%s", OAuthClientIdBodyKey, m_settings->m_appClientId.c_str()
|
||||
, OAuthClientSecretBodyKey, m_settings->m_clientSecret.c_str(), OAuthDeviceCodeBodyKey, m_cachedDeviceCode.c_str()
|
||||
, OAuthGrantTypeBodyKey, m_settings->m_grantType.c_str());
|
||||
|
||||
headers[OAUTH_CONTENT_TYPE_HEADER_KEY] = OAUTH_CONTENT_TYPE_HEADER_VALUE;
|
||||
headers[OAUTH_CONTENT_LENGTH_HEADER_KEY] = AZStd::to_string(body.length());
|
||||
headers[OAuthContentTypeHeaderKey] = OAuthContentTypeHeaderValue;
|
||||
headers[OAuthContentLengthHeaderKey] = AZStd::to_string(body.length());
|
||||
|
||||
HttpRequestor::HttpRequestorRequestBus::Broadcast(&HttpRequestor::HttpRequestorRequests::AddRequestWithHeadersAndBody, m_settings->m_oAuthTokensURL
|
||||
, Aws::Http::HttpMethod::HTTP_POST, headers, body
|
||||
@@ -125,7 +125,7 @@ namespace AWSClientAuth
|
||||
else
|
||||
{
|
||||
AuthenticationProviderNotificationBus::Broadcast(&AuthenticationProviderNotifications::OnDeviceCodeGrantConfirmSignInFail
|
||||
, jsonView.GetString(OAUTH_ERROR_RESPONSE_KEY).c_str());
|
||||
, jsonView.GetString(OAuthErrorResponseKey).c_str());
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -136,12 +136,12 @@ namespace AWSClientAuth
|
||||
void GoogleAuthenticationProvider::RefreshTokensAsync()
|
||||
{
|
||||
AZStd::map<AZStd::string, AZStd::string> headers;
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s&%s=%s", OAUTH_CLIENT_ID_BODY_KEY, m_settings->m_appClientId.c_str()
|
||||
, OAUTH_CLIENT_SECRET_BODY_KEY, m_settings->m_clientSecret.c_str()
|
||||
, OAUTH_GRANT_TYPE_BODY_KEY, OAUTH_REFRESH_TOKEN_BODY_VALUE, OAUTH_REFRESH_TOKEN_BODY_KEY, m_authenticationTokens.GetRefreshToken().c_str());
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s&%s=%s", OAuthClientIdBodyKey, m_settings->m_appClientId.c_str()
|
||||
, OAuthClientSecretBodyKey, m_settings->m_clientSecret.c_str()
|
||||
, OAuthGrantTypeBodyKey, OAuthRefreshTokenBodyValue, OAuthRefreshTokenBodyKey, m_authenticationTokens.GetRefreshToken().c_str());
|
||||
|
||||
headers[OAUTH_CONTENT_TYPE_HEADER_KEY] = OAUTH_CONTENT_TYPE_HEADER_VALUE;
|
||||
headers[OAUTH_CONTENT_LENGTH_HEADER_KEY] = AZStd::to_string(body.length());
|
||||
headers[OAuthContentTypeHeaderKey] = OAuthContentTypeHeaderValue;
|
||||
headers[OAuthContentLengthHeaderKey] = AZStd::to_string(body.length());
|
||||
|
||||
HttpRequestor::HttpRequestorRequestBus::Broadcast(&HttpRequestor::HttpRequestorRequests::AddRequestWithHeadersAndBody, m_settings->m_oAuthTokensURL
|
||||
, Aws::Http::HttpMethod::HTTP_POST, headers, body
|
||||
@@ -156,7 +156,7 @@ namespace AWSClientAuth
|
||||
else
|
||||
{
|
||||
AuthenticationProviderNotificationBus::Broadcast(&AuthenticationProviderNotifications::OnRefreshTokensFail
|
||||
, jsonView.GetString(OAUTH_ERROR_RESPONSE_KEY).c_str());
|
||||
, jsonView.GetString(OAuthErrorResponseKey).c_str());
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -164,9 +164,9 @@ namespace AWSClientAuth
|
||||
|
||||
void GoogleAuthenticationProvider::UpdateTokens(const Aws::Utils::Json::JsonView& jsonView)
|
||||
{
|
||||
m_authenticationTokens = AuthenticationTokens(jsonView.GetString(OAUTH_ACCESS_TOKEN_RESPONSE_KEY).c_str(),
|
||||
jsonView.GetString(OAUTH_REFRESH_TOKEN_RESPONSE_KEY).c_str() ,jsonView.GetString(OAUTH_ID_TOKEN_RESPONSE_KEY).c_str(), ProviderNameEnum::Google
|
||||
, jsonView.GetInteger(OAUTH_EXPIRES_IN_RESPONSE_KEY));
|
||||
m_authenticationTokens = AuthenticationTokens(jsonView.GetString(OAuthAccessTokenResponseKey).c_str(),
|
||||
jsonView.GetString(OAuthRefreshTokenResponseKey).c_str() ,jsonView.GetString(OAuthIdTokenResponseKey).c_str(), ProviderNameEnum::Google
|
||||
, jsonView.GetInteger(OAuthExpiresInResponseKey));
|
||||
}
|
||||
|
||||
} // namespace AWSClientAuth
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
namespace AWSClientAuth
|
||||
{
|
||||
constexpr char LWA_SETTINGS_PATH[] = "/AWS/LoginWithAmazon";
|
||||
constexpr char LWA_VERIFICATION_URL_RESPONSE_KEY[] = "verification_uri";
|
||||
constexpr char LwaSettingsPath[] = "/AWS/LoginWithAmazon";
|
||||
constexpr char LwaVerificationUrlResponseKey[] = "verification_uri";
|
||||
|
||||
LWAAuthenticationProvider::LWAAuthenticationProvider()
|
||||
{
|
||||
@@ -36,9 +36,9 @@ namespace AWSClientAuth
|
||||
|
||||
bool LWAAuthenticationProvider::Initialize(AZStd::weak_ptr<AZ::SettingsRegistryInterface> settingsRegistry)
|
||||
{
|
||||
if (!settingsRegistry.lock()->GetObject(m_settings.get(), azrtti_typeid(m_settings.get()), LWA_SETTINGS_PATH))
|
||||
if (!settingsRegistry.lock()->GetObject(m_settings.get(), azrtti_typeid(m_settings.get()), LwaSettingsPath))
|
||||
{
|
||||
AZ_Warning("AWSCognitoAuthenticationProvider", true, "Failed to get login with Amazon settings object for path %s", LWA_SETTINGS_PATH);
|
||||
AZ_Warning("AWSCognitoAuthenticationProvider", true, "Failed to get login with Amazon settings object for path %s", LwaSettingsPath);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -70,12 +70,12 @@ namespace AWSClientAuth
|
||||
void LWAAuthenticationProvider::DeviceCodeGrantSignInAsync()
|
||||
{
|
||||
// Set headers and body for device sign in http requests.
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s", OAUTH_RESPONSE_TYPE_BODY_KEY, m_settings->m_responseType.c_str()
|
||||
, OAUTH_CLIENT_ID_BODY_KEY, m_settings->m_appClientId.c_str(), OAUTH_SCOPE_BODY_KEY, OAUTH_SCOPE_BODY_VALUE);
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s", OAuthResponseTypeBodyKey, m_settings->m_responseType.c_str()
|
||||
, OAuthClientIdBodyKey, m_settings->m_appClientId.c_str(), OAuthScopeBodyKey, OAuthScopeBodyValue);
|
||||
|
||||
AZStd::map<AZStd::string, AZStd::string> headers;
|
||||
headers[OAUTH_CONTENT_TYPE_HEADER_KEY] = OAUTH_CONTENT_TYPE_HEADER_VALUE;
|
||||
headers[OAUTH_CONTENT_LENGTH_HEADER_KEY] = AZStd::to_string(body.length());
|
||||
headers[OAuthContentTypeHeaderKey] = OAuthContentTypeHeaderValue;
|
||||
headers[OAuthContentLengthHeaderKey] = AZStd::to_string(body.length());
|
||||
|
||||
HttpRequestor::HttpRequestorRequestBus::Broadcast(&HttpRequestor::HttpRequestorRequests::AddRequestWithHeadersAndBody, m_settings->m_oAuthCodeURL
|
||||
, Aws::Http::HttpMethod::HTTP_POST, headers, body
|
||||
@@ -83,17 +83,17 @@ namespace AWSClientAuth
|
||||
{
|
||||
if (responseCode == Aws::Http::HttpResponseCode::OK)
|
||||
{
|
||||
m_cachedUserCode = jsonView.GetString(OAUTH_USER_CODE_RESPONSE_KEY).c_str();
|
||||
m_cachedDeviceCode = jsonView.GetString(OAUTH_DEVICE_CODE_BODY_KEY).c_str();
|
||||
m_cachedUserCode = jsonView.GetString(OAuthUserCodeResponseKey).c_str();
|
||||
m_cachedDeviceCode = jsonView.GetString(OAuthDeviceCodeBodyKey).c_str();
|
||||
AuthenticationProviderNotificationBus::Broadcast(&AuthenticationProviderNotifications::OnDeviceCodeGrantSignInSuccess
|
||||
, jsonView.GetString(OAUTH_USER_CODE_RESPONSE_KEY).c_str()
|
||||
, jsonView.GetString(LWA_VERIFICATION_URL_RESPONSE_KEY).c_str()
|
||||
, jsonView.GetInteger(OAUTH_EXPIRES_IN_RESPONSE_KEY));
|
||||
, jsonView.GetString(OAuthUserCodeResponseKey).c_str()
|
||||
, jsonView.GetString(LwaVerificationUrlResponseKey).c_str()
|
||||
, jsonView.GetInteger(OAuthExpiresInResponseKey));
|
||||
}
|
||||
else
|
||||
{
|
||||
AuthenticationProviderNotificationBus::Broadcast(&AuthenticationProviderNotifications::OnDeviceCodeGrantSignInFail
|
||||
, jsonView.GetString(OAUTH_ERROR_RESPONSE_KEY).c_str());
|
||||
, jsonView.GetString(OAuthErrorResponseKey).c_str());
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -104,12 +104,12 @@ namespace AWSClientAuth
|
||||
void LWAAuthenticationProvider::DeviceCodeGrantConfirmSignInAsync()
|
||||
{
|
||||
// Set headers and body for device confirm sign in http requests.
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s", OAUTH_USER_CODE_RESPONSE_KEY, m_cachedUserCode.c_str()
|
||||
, OAUTH_GRANT_TYPE_BODY_KEY, m_settings->m_grantType.c_str(), OAUTH_DEVICE_CODE_BODY_KEY, m_cachedDeviceCode.c_str());
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s", OAuthUserCodeResponseKey, m_cachedUserCode.c_str()
|
||||
, OAuthGrantTypeBodyKey, m_settings->m_grantType.c_str(), OAuthDeviceCodeBodyKey, m_cachedDeviceCode.c_str());
|
||||
|
||||
AZStd::map<AZStd::string, AZStd::string> headers;
|
||||
headers[OAUTH_CONTENT_TYPE_HEADER_KEY] = OAUTH_CONTENT_TYPE_HEADER_VALUE;
|
||||
headers[OAUTH_CONTENT_LENGTH_HEADER_KEY] = AZStd::to_string(body.length());
|
||||
headers[OAuthContentTypeHeaderKey] = OAuthContentTypeHeaderValue;
|
||||
headers[OAuthContentLengthHeaderKey] = AZStd::to_string(body.length());
|
||||
|
||||
HttpRequestor::HttpRequestorRequestBus::Broadcast(&HttpRequestor::HttpRequestorRequests::AddRequestWithHeadersAndBody, m_settings->m_oAuthTokensURL
|
||||
, Aws::Http::HttpMethod::HTTP_POST, headers, body
|
||||
@@ -136,12 +136,12 @@ namespace AWSClientAuth
|
||||
void LWAAuthenticationProvider::RefreshTokensAsync()
|
||||
{
|
||||
// Set headers and body for device confirm sign in http requests.
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s", OAUTH_CLIENT_ID_BODY_KEY, m_settings->m_appClientId.c_str(), OAUTH_GRANT_TYPE_BODY_KEY,
|
||||
OAUTH_REFRESH_TOKEN_BODY_VALUE, OAUTH_REFRESH_TOKEN_BODY_KEY, m_authenticationTokens.GetRefreshToken().c_str());
|
||||
AZStd::string body = AZStd::string::format("%s=%s&%s=%s&%s=%s", OAuthClientIdBodyKey, m_settings->m_appClientId.c_str(), OAuthGrantTypeBodyKey,
|
||||
OAuthRefreshTokenBodyValue, OAuthRefreshTokenBodyKey, m_authenticationTokens.GetRefreshToken().c_str());
|
||||
|
||||
AZStd::map<AZStd::string, AZStd::string> headers;
|
||||
headers[OAUTH_CONTENT_TYPE_HEADER_KEY] = OAUTH_CONTENT_TYPE_HEADER_VALUE;
|
||||
headers[OAUTH_CONTENT_LENGTH_HEADER_KEY] = AZStd::to_string(body.length());
|
||||
headers[OAuthContentTypeHeaderKey] = OAuthContentTypeHeaderValue;
|
||||
headers[OAuthContentLengthHeaderKey] = AZStd::to_string(body.length());
|
||||
|
||||
HttpRequestor::HttpRequestorRequestBus::Broadcast(&HttpRequestor::HttpRequestorRequests::AddRequestWithHeadersAndBody, m_settings->m_oAuthTokensURL
|
||||
, Aws::Http::HttpMethod::HTTP_POST, headers, body
|
||||
@@ -165,9 +165,9 @@ namespace AWSClientAuth
|
||||
void LWAAuthenticationProvider::UpdateTokens(const Aws::Utils::Json::JsonView& jsonView)
|
||||
{
|
||||
// For Login with Amazon openId and access tokens are the same.
|
||||
m_authenticationTokens = AuthenticationTokens(jsonView.GetString(OAUTH_ACCESS_TOKEN_RESPONSE_KEY).c_str(), jsonView.GetString(OAUTH_REFRESH_TOKEN_RESPONSE_KEY).c_str(),
|
||||
jsonView.GetString(OAUTH_ACCESS_TOKEN_RESPONSE_KEY).c_str(), ProviderNameEnum::LoginWithAmazon
|
||||
, jsonView.GetInteger(OAUTH_EXPIRES_IN_RESPONSE_KEY));
|
||||
m_authenticationTokens = AuthenticationTokens(jsonView.GetString(OAuthAccessTokenResponseKey).c_str(), jsonView.GetString(OAuthRefreshTokenResponseKey).c_str(),
|
||||
jsonView.GetString(OAuthAccessTokenResponseKey).c_str(), ProviderNameEnum::LoginWithAmazon
|
||||
, jsonView.GetInteger(OAuthExpiresInResponseKey));
|
||||
}
|
||||
|
||||
} // namespace AWSClientAuth
|
||||
|
||||
+29
-19
@@ -13,6 +13,9 @@
|
||||
#include <AWSClientAuthBus.h>
|
||||
#include <AWSCoreBus.h>
|
||||
#include <Authorization/AWSCognitoAuthorizationController.h>
|
||||
#include <ResourceMapping/AWSResourceMappingBus.h>
|
||||
#include <AWSClientAuthResourceMappingConstants.h>
|
||||
|
||||
#include <AzCore/EBus/Internal/BusContainer.h>
|
||||
#include <AzCore/Jobs/JobFunction.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
@@ -22,7 +25,9 @@
|
||||
|
||||
namespace AWSClientAuth
|
||||
{
|
||||
constexpr char COGNITO_AUTHORIZATION_SETTINGS_PATH[] = "/AWS/CognitoIdentityPool";
|
||||
constexpr char CognitoAmazonLoginsId[] = "www.amazon.com";
|
||||
constexpr char CognitoGoogleLoginsId[] = "accounts.google.com";
|
||||
constexpr char CognitoUserPoolIdFormat[] = "cognito-idp.%s.amazonaws.com/%s";
|
||||
|
||||
AWSCognitoAuthorizationController::AWSCognitoAuthorizationController()
|
||||
{
|
||||
@@ -31,8 +36,6 @@ namespace AWSClientAuth
|
||||
AuthenticationProviderNotificationBus::Handler::BusConnect();
|
||||
AWSCore::AWSCredentialRequestBus::Handler::BusConnect();
|
||||
|
||||
m_settings = AZStd::make_unique<CognitoAuthorizationSettings>();
|
||||
|
||||
m_persistentCognitoIdentityProvider = std::make_shared<AWSClientAuthPersistentCognitoIdentityProvider>();
|
||||
m_persistentAnonymousCognitoIdentityProvider = std::make_shared<AWSClientAuthPersistentCognitoIdentityProvider>();
|
||||
|
||||
@@ -52,32 +55,39 @@ namespace AWSClientAuth
|
||||
m_persistentCognitoIdentityProvider.reset();
|
||||
m_persistentAnonymousCognitoIdentityProvider.reset();
|
||||
|
||||
m_settings.reset();
|
||||
|
||||
AWSCore::AWSCredentialRequestBus::Handler::BusDisconnect();
|
||||
AuthenticationProviderNotificationBus::Handler::BusDisconnect();
|
||||
AWSCognitoAuthorizationRequestBus::Handler::BusDisconnect();
|
||||
AZ::Interface<IAWSCognitoAuthorizationRequests>::Unregister(this);
|
||||
}
|
||||
|
||||
bool AWSCognitoAuthorizationController::Initialize(const AZStd::string& settingsRegistryPath)
|
||||
bool AWSCognitoAuthorizationController::Initialize()
|
||||
{
|
||||
AZStd::unique_ptr<AZ::SettingsRegistryInterface> settingsRegistry = AZStd::make_unique<AZ::SettingsRegistryImpl>();
|
||||
AWSCore::AWSResourceMappingRequestBus::BroadcastResult(
|
||||
m_awsAccountId, &AWSCore::AWSResourceMappingRequests::GetDefaultAccountId);
|
||||
|
||||
if (!settingsRegistry->MergeSettingsFile(settingsRegistryPath, AZ::SettingsRegistryInterface::Format::JsonMergePatch))
|
||||
AWSCore::AWSResourceMappingRequestBus::BroadcastResult(
|
||||
m_cognitoIdentityPoolId, &AWSCore::AWSResourceMappingRequests::GetResourceNameId, CognitoIdentityPoolIdResourceMappingKey);
|
||||
|
||||
if (m_awsAccountId.empty() || m_cognitoIdentityPoolId.empty())
|
||||
{
|
||||
AZ_Error("AWSCognitoAuthorizationController", true, "Failed to merge settings file for path %s", settingsRegistryPath.c_str());
|
||||
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.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!settingsRegistry->GetObject(m_settings.get(), azrtti_typeid(m_settings.get()), COGNITO_AUTHORIZATION_SETTINGS_PATH))
|
||||
{
|
||||
AZ_Error("AWSCognitoAuthorizationController", true, "Failed to get settings object for path %s", COGNITO_AUTHORIZATION_SETTINGS_PATH);
|
||||
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.");
|
||||
|
||||
m_persistentCognitoIdentityProvider->Initialize(m_settings->m_awsAccountId.c_str(), m_settings->m_cognitoIdentityPoolId.c_str());
|
||||
m_persistentAnonymousCognitoIdentityProvider->Initialize(m_settings->m_awsAccountId.c_str(), m_settings->m_cognitoIdentityPoolId.c_str());
|
||||
AZStd::string defaultRegion;
|
||||
AWSCore::AWSResourceMappingRequestBus::BroadcastResult(
|
||||
defaultRegion, &AWSCore::AWSResourceMappingRequests::GetDefaultRegion);
|
||||
m_formattedCognitoUserPoolId = AZStd::string::format(CognitoUserPoolIdFormat, defaultRegion.c_str(), userPoolId.c_str());
|
||||
|
||||
m_persistentCognitoIdentityProvider->Initialize(m_awsAccountId.c_str(), m_cognitoIdentityPoolId.c_str());
|
||||
m_persistentAnonymousCognitoIdentityProvider->Initialize(m_awsAccountId.c_str(), m_cognitoIdentityPoolId.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -182,15 +192,15 @@ namespace AWSClientAuth
|
||||
{
|
||||
case ProviderNameEnum::AWSCognitoIDP:
|
||||
{
|
||||
return m_settings->m_cognitoUserPoolId;
|
||||
return m_formattedCognitoUserPoolId;
|
||||
}
|
||||
case ProviderNameEnum::LoginWithAmazon:
|
||||
{
|
||||
return m_settings->m_loginWithAmazonId;
|
||||
return CognitoAmazonLoginsId;
|
||||
}
|
||||
case ProviderNameEnum::Google:
|
||||
{
|
||||
return m_settings->m_googleId;
|
||||
return CognitoGoogleLoginsId;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
+13
-27
@@ -14,7 +14,9 @@
|
||||
|
||||
#include <UserManagement/AWSCognitoUserManagementController.h>
|
||||
#include <AWSClientAuthBus.h>
|
||||
#include <AWSClientAuthResourceMappingConstants.h>
|
||||
#include <AWSCoreBus.h>
|
||||
#include <ResourceMapping/AWSResourceMappingBus.h>
|
||||
|
||||
#include <aws/core/utils/Outcome.h>
|
||||
#include <aws/core/utils/memory/stl/AWSVector.h>
|
||||
@@ -35,41 +37,25 @@
|
||||
|
||||
namespace AWSClientAuth
|
||||
{
|
||||
constexpr char COGNITO_USER_POOL[] = "/AWS/CognitoUserPool";
|
||||
|
||||
AWSCognitoUserManagementController::AWSCognitoUserManagementController()
|
||||
{
|
||||
AZ::Interface<IAWSCognitoUserManagementRequests>::Register(this);
|
||||
AWSCognitoUserManagementRequestBus::Handler::BusConnect();
|
||||
|
||||
m_settings = AZStd::make_unique<AWSCognitoUserManagementSetting>();
|
||||
}
|
||||
|
||||
AWSCognitoUserManagementController::~AWSCognitoUserManagementController()
|
||||
{
|
||||
m_settings.reset();
|
||||
|
||||
AWSCognitoUserManagementRequestBus::Handler::BusDisconnect();
|
||||
AZ::Interface<IAWSCognitoUserManagementRequests>::Unregister(this);
|
||||
}
|
||||
|
||||
bool AWSCognitoUserManagementController::Initialize(const AZStd::string& settingsRegistryPath)
|
||||
bool AWSCognitoUserManagementController::Initialize()
|
||||
{
|
||||
AZStd::unique_ptr<AZ::SettingsRegistryInterface> settingsRegistry = AZStd::make_unique<AZ::SettingsRegistryImpl>();
|
||||
|
||||
if (!settingsRegistry->MergeSettingsFile(settingsRegistryPath, AZ::SettingsRegistryInterface::Format::JsonMergePatch))
|
||||
{
|
||||
AZ_Error("AWSCognitoUserManagementController", true, "Failed to merge settings file for path %s", settingsRegistryPath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!settingsRegistry->GetObject(m_settings.get(), azrtti_typeid(m_settings.get()), COGNITO_USER_POOL))
|
||||
{
|
||||
AZ_Error("AWSCognitoUserManagementController", true, "Failed to get settings object for path %s", COGNITO_USER_POOL);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
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.");
|
||||
return !m_cognitoAppClientId.empty();
|
||||
}
|
||||
|
||||
// Call Cognito user pool sign up using email. Confirmation code sent to the email set.
|
||||
@@ -85,7 +71,7 @@ namespace AWSClientAuth
|
||||
AZ::Job* emailSignUpJob = AZ::CreateJobFunction([this, cognitoIdentityProviderClient, username, password, email]()
|
||||
{
|
||||
Aws::CognitoIdentityProvider::Model::SignUpRequest signUpRequest;
|
||||
signUpRequest.SetClientId(m_settings->m_appClientId.c_str());
|
||||
signUpRequest.SetClientId(m_cognitoAppClientId.c_str());
|
||||
signUpRequest.SetUsername(username.c_str());
|
||||
signUpRequest.SetPassword(password.c_str());
|
||||
|
||||
@@ -123,7 +109,7 @@ namespace AWSClientAuth
|
||||
AZ::Job* phoneSignUpJob = AZ::CreateJobFunction([this, cognitoIdentityProviderClient, username, password, phoneNumber]()
|
||||
{
|
||||
Aws::CognitoIdentityProvider::Model::SignUpRequest signUpRequest;
|
||||
signUpRequest.SetClientId(m_settings->m_appClientId.c_str());
|
||||
signUpRequest.SetClientId(m_cognitoAppClientId.c_str());
|
||||
signUpRequest.SetUsername(username.c_str());
|
||||
signUpRequest.SetPassword(password.c_str());
|
||||
|
||||
@@ -163,7 +149,7 @@ namespace AWSClientAuth
|
||||
AZ::Job* confirmSignUpJob = AZ::CreateJobFunction([this, cognitoIdentityProviderClient, username, confirmationCode]()
|
||||
{
|
||||
Aws::CognitoIdentityProvider::Model::ConfirmSignUpRequest confirmSignupRequest;
|
||||
confirmSignupRequest.SetClientId(m_settings->m_appClientId.c_str());
|
||||
confirmSignupRequest.SetClientId(m_cognitoAppClientId.c_str());
|
||||
confirmSignupRequest.SetUsername(username.c_str());
|
||||
confirmSignupRequest.SetConfirmationCode(confirmationCode.c_str());
|
||||
|
||||
@@ -192,7 +178,7 @@ namespace AWSClientAuth
|
||||
AZ::Job* forgotPasswordJob = AZ::CreateJobFunction([this, cognitoIdentityProviderClient, username]()
|
||||
{
|
||||
Aws::CognitoIdentityProvider::Model::ForgotPasswordRequest forgotPasswordRequest;
|
||||
forgotPasswordRequest.SetClientId(m_settings->m_appClientId.c_str());
|
||||
forgotPasswordRequest.SetClientId(m_cognitoAppClientId.c_str());
|
||||
forgotPasswordRequest.SetUsername(username.c_str());
|
||||
|
||||
Aws::CognitoIdentityProvider::Model::ForgotPasswordOutcome forgotPasswordOutcome{ cognitoIdentityProviderClient->ForgotPassword(forgotPasswordRequest) };
|
||||
@@ -220,7 +206,7 @@ namespace AWSClientAuth
|
||||
AZ::Job* confirmForgotPasswordJob = AZ::CreateJobFunction([this, cognitoIdentityProviderClient, username, confirmationCode, newPassword]()
|
||||
{
|
||||
Aws::CognitoIdentityProvider::Model::ConfirmForgotPasswordRequest confirmForgotPasswordRequest;
|
||||
confirmForgotPasswordRequest.SetClientId(m_settings->m_appClientId.c_str());
|
||||
confirmForgotPasswordRequest.SetClientId(m_cognitoAppClientId.c_str());
|
||||
confirmForgotPasswordRequest.SetUsername(username.c_str());
|
||||
confirmForgotPasswordRequest.SetConfirmationCode(confirmationCode.c_str());
|
||||
confirmForgotPasswordRequest.SetPassword(newPassword.c_str());
|
||||
|
||||
Reference in New Issue
Block a user