AuthenticationTokens.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/Preprocessor/Enum.h>
  10. #include <AzCore/std/string/string.h>
  11. #include <AzCore/std/chrono/chrono.h>
  12. #include <AzCore/RTTI/BehaviorContext.h>
  13. #include <AzCore/Serialization/EditContext.h>
  14. namespace AWSClientAuth
  15. {
  16. AZ_ENUM_CLASS(ProviderNameEnum, None, AWSCognitoIDP, LoginWithAmazon, Twitch, Google, Apple, Facebook);
  17. //! Used to share authentication tokens to caller and to AWSCognitoAuthorizationController.
  18. class AuthenticationTokens
  19. {
  20. public:
  21. AZ_TYPE_INFO(AuthenticationTokens, "{F965D1B2-9DE3-4900-B44B-E58D9F083ACB}");
  22. AuthenticationTokens();
  23. AuthenticationTokens(const AuthenticationTokens& other);
  24. AuthenticationTokens(const AZStd::string& accessToken, const AZStd::string& refreshToken, const AZStd::string& openIdToken
  25. , const ProviderNameEnum& providerName, int tokensExpireTimeSeconds);
  26. //! Compares current time stamp to expired time stamp.
  27. //! @return True if current TS less than expiry TS.
  28. bool AreTokensValid() const;
  29. //! @return Open id token from authentication.
  30. AZStd::string GetOpenIdToken() const;
  31. //! @return Access token from authentication.
  32. AZStd::string GetAccessToken() const;
  33. //! @return Refresh token from authentication.
  34. AZStd::string GetRefreshToken() const;
  35. //! @return Provide name for the tokens.
  36. ProviderNameEnum GetProviderName() const;
  37. //! @return Expiration time in seconds.
  38. int GetTokensExpireTimeSeconds() const;
  39. static void Reflect(AZ::ReflectContext* context);
  40. private:
  41. int m_tokensExpireTimeSeconds = 0;
  42. AZStd::string m_accessToken;
  43. AZStd::string m_refreshToken;
  44. AZStd::string m_openIdToken;
  45. ProviderNameEnum m_providerName;
  46. AZStd::chrono::steady_clock::time_point m_tokensExpireTimeStamp;
  47. };
  48. } // namespace AWSClientAuth