AuthenticationProviderManager.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <AzCore/std/smart_ptr/unique_ptr.h>
  10. #include <AzCore/std/containers/map.h>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <Authentication/AuthenticationProviderBus.h>
  13. #include <Authentication/AuthenticationProviderScriptCanvasBus.h>
  14. #include <Authentication/AuthenticationProviderInterface.h>
  15. #include <Authentication/AuthenticationTokens.h>
  16. namespace AWSClientAuth
  17. {
  18. //! Manages various authentication provider implementations and implements AuthenticationProvider Request bus.
  19. class AuthenticationProviderManager
  20. : public AuthenticationProviderRequestBus::Handler
  21. , public AuthenticationProviderScriptCanvasRequestBus::Handler
  22. {
  23. public:
  24. AZ_RTTI(AuthenticationProviderManager, "{45813BA5-9A46-4A2A-A923-C79CFBA0E63D}", IAuthenticationProviderRequests);
  25. AuthenticationProviderManager();
  26. virtual ~AuthenticationProviderManager();
  27. protected:
  28. // AuthenticationProviderRequestsBus Interface
  29. bool Initialize(const AZStd::vector<ProviderNameEnum>& providerNames) override;
  30. void PasswordGrantSingleFactorSignInAsync(const ProviderNameEnum& providerName, const AZStd::string& username, const AZStd::string& password) override;
  31. void PasswordGrantMultiFactorSignInAsync(const ProviderNameEnum& providerName, const AZStd::string& username, const AZStd::string& password) override;
  32. void PasswordGrantMultiFactorConfirmSignInAsync(const ProviderNameEnum& providerName, const AZStd::string& username, const AZStd::string& confirmationCode) override;
  33. void DeviceCodeGrantSignInAsync(const ProviderNameEnum& providerName) override;
  34. void DeviceCodeGrantConfirmSignInAsync(const ProviderNameEnum& providerName) override;
  35. void RefreshTokensAsync(const ProviderNameEnum& providerName) override;
  36. void GetTokensWithRefreshAsync(const ProviderNameEnum& providerName) override;
  37. bool IsSignedIn(const ProviderNameEnum& providerName) override;
  38. bool SignOut(const ProviderNameEnum& providerName) override;
  39. AuthenticationTokens GetAuthenticationTokens(const ProviderNameEnum& providerName) override;
  40. // AuthenticationProviderScriptCanvasRequest interface
  41. bool Initialize(const AZStd::vector<AZStd::string>& providerNames) override;
  42. void PasswordGrantSingleFactorSignInAsync(
  43. const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password) override;
  44. void PasswordGrantMultiFactorSignInAsync(
  45. const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password) override;
  46. void PasswordGrantMultiFactorConfirmSignInAsync(
  47. const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& confirmationCode) override;
  48. void DeviceCodeGrantSignInAsync(const AZStd::string& providerName) override;
  49. void DeviceCodeGrantConfirmSignInAsync(const AZStd::string& providerName) override;
  50. void RefreshTokensAsync(const AZStd::string& providerName) override;
  51. void GetTokensWithRefreshAsync(const AZStd::string& providerName) override;
  52. bool IsSignedIn(const AZStd::string& providerName) override;
  53. bool SignOut(const AZStd::string& providerName) override;
  54. AuthenticationTokens GetAuthenticationTokens(const AZStd::string& providerName) override;
  55. virtual AZStd::unique_ptr<AuthenticationProviderInterface> CreateAuthenticationProviderObject(const ProviderNameEnum& providerName);
  56. AZStd::map<ProviderNameEnum, AZStd::unique_ptr<AuthenticationProviderInterface>> m_authenticationProvidersMap;
  57. private:
  58. bool IsProviderInitialized(const ProviderNameEnum& providerName);
  59. void ResetProviders();
  60. ProviderNameEnum GetProviderNameEnum(AZStd::string name);
  61. };
  62. } // namespace AWSClientAuth