AWS SDK for C++  1.8.55
AWS SDK for C++
PersistentCognitoIdentityProvider.h
Go to the documentation of this file.
1 
5 #pragma once
6 
10 #include <mutex>
11 
12 namespace Aws
13 {
14  namespace Utils
15  {
16  namespace Json
17  {
18  class JsonView;
19  class JsonValue;
20  }
21  }
22  namespace Auth
23  {
25  {
26  LoginAccessTokens() : longTermTokenExpiry(0) {}
30  };
31 
33  {
34  public:
35  virtual ~PersistentCognitoIdentityProvider() = default;
36  virtual bool HasIdentityId() const = 0;
37  virtual bool HasLogins() const = 0;
38  virtual Aws::String GetIdentityId() const = 0;
39  virtual Aws::Map<Aws::String, LoginAccessTokens> GetLogins() = 0;
40  virtual Aws::String GetAccountId() const = 0;
41  virtual Aws::String GetIdentityPoolId() const = 0;
42  virtual void PersistIdentityId(const Aws::String&) = 0;
43  virtual void PersistLogins(const Aws::Map<Aws::String, LoginAccessTokens>&) = 0;
44  inline void ClearLogins() { PersistLogins(Aws::Map<Aws::String, LoginAccessTokens>()); }
45  inline void ClearIdentity() { PersistIdentityId(""); }
46  inline void Logout() { ClearIdentity(); ClearLogins(); }
47 
48  inline void SetLoginsUpdatedCallback(const std::function<void(const PersistentCognitoIdentityProvider&)>& callback)
49  {
50  m_loginsUpdatedCallback = callback;
51  }
52 
53  inline void SetIdentityIdUpdatedCallback(const std::function<void(const PersistentCognitoIdentityProvider&)>& callback)
54  {
55  m_identityIdUpdatedCallback = callback;
56  }
57 
58  protected:
59  std::function<void(const PersistentCognitoIdentityProvider&)> m_loginsUpdatedCallback;
60  std::function<void(const PersistentCognitoIdentityProvider&)> m_identityIdUpdatedCallback;
61  };
62 
64  {
65  public:
66  PersistentCognitoIdentityProvider_JsonFileImpl(const Aws::String& identityPoolId, const Aws::String& accountId, bool disableCaching = false);
67  PersistentCognitoIdentityProvider_JsonFileImpl(const Aws::String& identityPoolId, const Aws::String& accountId, const char* identitiesFilePath, bool disableCaching = false);
68 
69  bool HasIdentityId() const override;
70  bool HasLogins() const override;
71  Aws::String GetIdentityId() const override;
72  Aws::Map<Aws::String, LoginAccessTokens> GetLogins() override;
73  Aws::String GetAccountId() const override { return m_accountId; }
74  Aws::String GetIdentityPoolId() const override { return m_identityPoolId; }
75  void PersistIdentityId(const Aws::String&) override;
76  void PersistLogins(const Aws::Map<Aws::String, LoginAccessTokens>&) override;
77 
78  private:
79  Utils::Json::JsonValue LoadJsonDocFromFile() const;
80  void PersistChangesToFile(const Utils::Json::JsonValue&) const;
81  void LoadAndParseDoc();
82 
84 
85  std::mutex m_docMutex;
86  Aws::String m_identityPoolId;
87  Aws::String m_accountId;
88  Aws::String m_identityId;
90  Aws::String m_identityFilePath;
91  bool m_disableCaching;
92  };
93 
95  }
96 }
PersistentCognitoIdentityProvider_JsonFileImpl DefaultPersistentCognitoIdentityProvider
std::function< void(const PersistentCognitoIdentityProvider &)> m_identityIdUpdatedCallback
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition: AWSMap.h:19
void SetLoginsUpdatedCallback(const std::function< void(const PersistentCognitoIdentityProvider &)> &callback)
std::function< void(const PersistentCognitoIdentityProvider &)> m_loginsUpdatedCallback
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
#define AWS_IDENTITY_MANAGEMENT_API
void SetIdentityIdUpdatedCallback(const std::function< void(const PersistentCognitoIdentityProvider &)> &callback)