AuthenticationProviderScriptCanvasBus.h 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/EBus/EBus.h>
  10. #include <Authentication/AuthenticationTokens.h>
  11. namespace AWSClientAuth
  12. {
  13. //! Abstract class for authentication provider script canvas requests.
  14. //! Private class to allow provide names to be string type instead of an enum as behavior context does not work well with enum's.
  15. class IAuthenticationProviderScriptCanvasRequests
  16. {
  17. public:
  18. AZ_TYPE_INFO(IAuthenticationProviderScriptCanvasRequests, "{A8FD915F-9FF2-4BA3-8AA0-8CF7A94A323B}");
  19. //! Parse the settings file for required settings for authentication providers. Instantiate and initialize authentication providers
  20. //! @param providerNames List of provider names to instantiate and initialize for Authentication.
  21. //! @return bool True: if all providers initialized successfully. False: If any provider fails initialization.
  22. virtual bool Initialize(const AZStd::vector<AZStd::string>& providerNames) = 0;
  23. //! Checks if user is signed in.
  24. //! If access tokens are available and not expired.
  25. //! @param providerName Provider to check signed in for
  26. //! @return bool True if valid access token available, else False
  27. virtual bool IsSignedIn(const AZStd::string& providerName) = 0;
  28. //! Get cached tokens from last last successful sign-in for the provider.
  29. //! @param providerName Provider to get authentication tokens
  30. //! @return AuthenticationTokens tokens from successful authentication.
  31. virtual AuthenticationTokens GetAuthenticationTokens(const AZStd::string& providerName) = 0;
  32. // Below methods have corresponding notifications for success and failures.
  33. //! Call sign in endpoint for provider password grant flow.
  34. //! @param providerName Provider to call sign in.
  35. //! @param username Username to use to for sign in.
  36. //! @param password Password to use to for sign in.
  37. virtual void PasswordGrantSingleFactorSignInAsync(const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password) = 0;
  38. //! Call sign in endpoint for provider password grant multi factor authentication flow.
  39. //! @param providerName Provider to call MFA sign in.
  40. //! @param username Username to use for MFA sign in.
  41. //! @param password Password to use for MFA sign in.
  42. virtual void PasswordGrantMultiFactorSignInAsync(const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& password) = 0;
  43. //! Call confirm endpoint for provider password grant multi factor authentication flow .
  44. //! @param providerName Provider to call MFA confirm sign in.
  45. //! @param username Username to use for MFA confirm.
  46. //! @param confirmationCode Confirmation code (sent to email/text) to use for MFA confirm.
  47. virtual void PasswordGrantMultiFactorConfirmSignInAsync(const AZStd::string& providerName, const AZStd::string& username, const AZStd::string& confirmationCode) = 0;
  48. //! Call code-pair endpoint for provider device grant flow.
  49. //! @param providerName Provider to call device sign in.
  50. virtual void DeviceCodeGrantSignInAsync(const AZStd::string& providerName) = 0;
  51. //! Call tokens endpoint for provider device grant flow.
  52. //! @param providerName Provider to call device confirm sign in.
  53. virtual void DeviceCodeGrantConfirmSignInAsync(const AZStd::string& providerName) = 0;
  54. //! Call refresh endpoint for provider refresh grant flow.
  55. //! @param providerName Provider to call refresh tokens.
  56. virtual void RefreshTokensAsync(const AZStd::string& providerName) = 0;
  57. //! Call refresh token if token not valid. If token valid, fires corresponding event.
  58. //! @param providerName Provider to get access token for.
  59. //! events: OnRefreshTokensSuccess, OnRefreshTokensFail
  60. virtual void GetTokensWithRefreshAsync(const AZStd::string& providerName) = 0;
  61. //! Signs user out.
  62. //! Clears all cached tokens.
  63. //! @param providerName Provider to sign out.
  64. //! @return bool True: Successfully sign out.
  65. virtual bool SignOut(const AZStd::string& providerName) = 0;
  66. //////////////////////////////////////////////////////////////////////////
  67. };
  68. //! Authentication Request bus for different supported providers.
  69. class AuthenticationProviderScriptCanvasRequests
  70. : public AZ::EBusTraits
  71. {
  72. public:
  73. //////////////////////////////////////////////////////////////////////////
  74. // EBusTraits overrides
  75. using MutexType = AZ::NullMutex;
  76. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  77. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  78. //////////////////////////////////////////////////////////////////////////
  79. };
  80. using AuthenticationProviderScriptCanvasRequestBus = AZ::EBus<IAuthenticationProviderScriptCanvasRequests, AuthenticationProviderScriptCanvasRequests>;
  81. } // namespace AWSClientAuth