AWS SDK for C++  0.14.3
AWS SDK for C++
CognitoCachingCredentialsProvider.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #pragma once
17 
22 #include <mutex>
23 
24 namespace Aws
25 {
26  namespace Auth
27  {
28  class PersistentCognitoIdentityProvider;
29 
35  {
36  public:
37  AWSCredentials GetAWSCredentials() override;
38 
39  protected:
44  CognitoCachingCredentialsProvider(const std::shared_ptr<PersistentCognitoIdentityProvider>& m_identityRepository,
45  const std::shared_ptr<CognitoIdentity::CognitoIdentityClient>& cognitoIdentityClient = nullptr);
46 
47  virtual CognitoIdentity::Model::GetCredentialsForIdentityOutcome GetCredentialsFromCognito() const = 0;
48 
49  bool IsTimeExpired(double expiry);
50 
51  std::shared_ptr<CognitoIdentity::CognitoIdentityClient> m_cognitoIdentityClient;
52  std::shared_ptr<PersistentCognitoIdentityProvider> m_identityRepository;
53 
54  private:
55  void OnLoginsUpdated(const PersistentCognitoIdentityProvider&);
56 
57  AWSCredentials m_cachedCredentials;
58  std::atomic<double> m_expiry;
59  std::mutex m_credsMutex;
60  };
61 
67  {
68  public:
73  CognitoCachingAnonymousCredentialsProvider(const std::shared_ptr<PersistentCognitoIdentityProvider>& identityRepository,
74  const std::shared_ptr<CognitoIdentity::CognitoIdentityClient>& cognitoIdentityClient = nullptr);
75 
76  CognitoCachingAnonymousCredentialsProvider(const Aws::String& accountId, const Aws::String& identityPoolId,
77  const std::shared_ptr<CognitoIdentity::CognitoIdentityClient>& cognitoIdentityClient = nullptr);
78 
79  protected:
80  CognitoIdentity::Model::GetCredentialsForIdentityOutcome GetCredentialsFromCognito() const override;
81  };
82 
88  {
89  public:
94  CognitoCachingAuthenticatedCredentialsProvider(const std::shared_ptr<PersistentCognitoIdentityProvider>& identityRepository,
95  const std::shared_ptr<CognitoIdentity::CognitoIdentityClient>& cognitoIdentityClient = nullptr);
96 
97  protected:
98  CognitoIdentity::Model::GetCredentialsForIdentityOutcome GetCredentialsFromCognito() const override;
99  };
100  }
101 }
std::shared_ptr< CognitoIdentity::CognitoIdentityClient > m_cognitoIdentityClient
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
#define AWS_IDENTITY_MANAGEMENT_API
std::shared_ptr< PersistentCognitoIdentityProvider > m_identityRepository
JSON (JavaScript Object Notation).