AWSCognitoAuthorizationController.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <Authorization/AWSCognitoAuthorizationBus.h>
  10. #include <Authorization/AWSClientAuthCognitoCachingAuthenticatedCredentialsProvider.h>
  11. #include <Authorization/AWSClientAuthPersistentCognitoIdentityProvider.h>
  12. #include <Authentication/AuthenticationProviderBus.h>
  13. #include <Credential/AWSCredentialBus.h>
  14. #include <aws/cognito-identity/CognitoIdentityClient.h>
  15. #include <aws/identity-management/auth/CognitoCachingCredentialsProvider.h>
  16. namespace AWSClientAuth
  17. {
  18. //! Implements AWS Cognito Identity pool authorization.
  19. class AWSCognitoAuthorizationController
  20. : public AWSCognitoAuthorizationRequestBus::Handler
  21. , public AuthenticationProviderNotificationBus::Handler
  22. , public AWSCore::AWSCredentialRequestBus::Handler
  23. {
  24. public:
  25. AZ_RTTI(AWSCognitoAuthorizationController, "{0E731ED1-2F08-4B3C-9282-D452700F58D1}", IAWSCognitoAuthorizationRequests);
  26. AWSCognitoAuthorizationController();
  27. virtual ~AWSCognitoAuthorizationController();
  28. // AWSCognitoAuthorizationRequestsBus interface methods
  29. bool Initialize() override;
  30. void Reset() override;
  31. AZStd::string GetIdentityId() override;
  32. bool HasPersistedLogins() override;
  33. std::shared_ptr<Aws::Auth::AWSCredentialsProvider> GetCognitoCredentialsProvider() override;
  34. std::shared_ptr<Aws::Auth::AWSCredentialsProvider> GetAnonymousCognitoCredentialsProvider() override;
  35. void RequestAWSCredentialsAsync() override;
  36. protected:
  37. // AuthenticationProviderNotificationsBus interface. Update persistent login tokens on successful sign in.
  38. void OnPasswordGrantSingleFactorSignInSuccess(const AWSClientAuth::AuthenticationTokens& authenticationTokens) override;
  39. void OnPasswordGrantMultiFactorConfirmSignInSuccess(const AWSClientAuth::AuthenticationTokens& authenticationTokens) override;
  40. void OnDeviceCodeGrantConfirmSignInSuccess(const AWSClientAuth::AuthenticationTokens& authenticationTokens) override;
  41. void OnRefreshTokensSuccess(const AWSClientAuth::AuthenticationTokens& authenticationTokens) override;
  42. void OnSignOut(const ProviderNameEnum& provideName) override;
  43. // AWSCredentialRequestBus interface implementation
  44. int GetCredentialHandlerOrder() const override;
  45. std::shared_ptr<Aws::Auth::AWSCredentialsProvider> GetCredentialsProvider() override;
  46. std::shared_ptr<AWSClientAuthPersistentCognitoIdentityProvider> m_persistentCognitoIdentityProvider;
  47. std::shared_ptr<AWSClientAuthPersistentCognitoIdentityProvider> m_persistentAnonymousCognitoIdentityProvider;
  48. std::shared_ptr<AWSClientAuthCognitoCachingAuthenticatedCredentialsProvider> m_cognitoCachingCredentialsProvider;
  49. std::shared_ptr<AWSClientAuthCachingAnonymousCredsProvider> m_cognitoCachingAnonymousCredentialsProvider;
  50. AZStd::string m_cognitoIdentityPoolId;
  51. AZStd::string m_formattedCognitoUserPoolId;
  52. AZStd::string m_awsAccountId;
  53. private:
  54. void PersistLoginsAndRefreshAWSCredentials(const AuthenticationTokens& authenticationTokens);
  55. AZStd::string GetAuthenticationProviderId(const ProviderNameEnum& providerName);
  56. AZStd::mutex m_persistentCognitoIdentityProviderMutex;
  57. AZStd::mutex m_persistentAnonymousCognitoIdentityProviderMutex;
  58. };
  59. } // namespace AWSClientAuth