Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a new CognitoAWSCredentials instance, which will use the
        /// specified Amazon Cognito identity pool to make a requests to the
        /// AWS Security Token Service (STS) to request short lived session credentials.
        /// </summary>
        /// <param name="accountId">The AWS accountId for the account with Amazon Cognito</param>
        /// <param name="identityPoolId">The Amazon Cogntio identity pool to use</param>
        /// <param name="unAuthRoleArn">The ARN of the IAM Role that will be assumed when unauthenticated</param>
        /// <param name="authRoleArn">The ARN of the IAM Role that will be assumed when authenticated</param>
        /// <param name="region">Region to use when accessing Amazon Cognito and AWS Security Token Service.</param>
        public CachingCognitoAWSCredentials(
            string accountId, string identityPoolId,
            string unAuthRoleArn, string authRoleArn,
            RegionEndpoint region)
            : this(
                unAuthRoleArn, authRoleArn,
                new AmazonCognitoIdentityProvider(accountId, identityPoolId, new AnonymousAWSCredentials(), region),
                new AmazonSecurityTokenServiceClient(new AnonymousAWSCredentials(), region))
        {
            if (string.IsNullOrEmpty(accountId))
            {
                throw new ArgumentNullException("accountId cannot be null");
            }
            if (string.IsNullOrEmpty(identityPoolId))
            {
                throw new ArgumentNullException("identityPoolId cannot be null");
            }
            if (string.IsNullOrEmpty(unAuthRoleArn) && string.IsNullOrEmpty(authRoleArn))
            {
                throw new ArgumentNullException("Both unAuthRoleArn and authRoleArn cannot be null");
            }
#if UNITY_WEBPLAYER
            _persistentStore = new InMemoryKVStore();
#else
            _persistentStore = new SQLiteKVStore();
#endif

            string IP = _persistentStore.Get(IP_KEY);

            if (!string.IsNullOrEmpty(IP) && 0 == IP.CompareTo(identityPoolId))
            {
                IdentityProvider.UpdateIdentity(_persistentStore.Get(ID_KEY));

                AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "CachingCognitoAWSCredentials", "Loaded Cached IdentityID from LocalStorage");
                loadCachedCredentials();
            }
            else if (!string.IsNullOrEmpty(IP))
            {
                // identity pool id is different from whats caching
                Clear();
            }

            IdentityProvider.IdentityChangedEvent += delegate(object sender, IdentityChangedArgs e)
            {
                if (!string.IsNullOrEmpty(e.OldIdentityId))
                {
                    this.Clear();
                }
                if (string.IsNullOrEmpty(_persistentStore.Get(IP_KEY)))
                {
                    // identity pool id is not cached
                    _persistentStore.Put(IP_KEY, this.IdentityProvider.IdentityPoolId);
                }
                // caching identity whenever new identity is found
                _persistentStore.Put(ID_KEY, e.NewIdentityId);
                AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "CachingCognitoAWSCredentials", "Saved identityID to LocalStorage");
            };
        }
Ejemplo n.º 2
0
 private void saveCredentials()
 {
     if (_sessionCredentials != null)
     {
         _persistentStore.Put(namespacedKey(AK_KEY), _sessionCredentials.Credentials.AccessKey);
         _persistentStore.Put(namespacedKey(SK_KEY), _sessionCredentials.Credentials.SecretKey);
         _persistentStore.Put(namespacedKey(ST_KEY), _sessionCredentials.Credentials.Token);
         _persistentStore.Put(namespacedKey(EXP_KEY), _sessionCredentials.Expiration.Ticks.ToString());
         _persistentStore.Put(namespacedKey(ID_KEY), IdentityProvider.GetCurrentIdentityId());
         AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "CognitoAWSCredentials", "Saved credentials to LocalStorage");
     }
 }
 /// <summary>
 /// Call back to policy once the delivery has been completed
 /// On Successful delivery the timestamp is recorded on the local storage
 /// </summary>
 /// <param name="isSuccessful">If set to <c>true</c> successful.</param>
 public void HandleDeliveryAttempt(bool isSuccessful)
 {
     //persist the timestamp
     if (isSuccessful)
     {
         _persistStore.Put(LAST_SUCCESSFUL_DELIVERY_TIME_STAMP_KEY, DateTime.Now.Subtract(start).Ticks.ToString());
     }
 }
Ejemplo n.º 4
0
        public void TestPutGet()
        {
            string key   = "k1";
            string value = "v1";

            string  name  = "test";
            KVStore store = KVStore.Open(name);

            store.Put(key, value);

            Assert.AreEqual(name, store.Name);
            Assert.AreEqual(value, store.get(key));
        }
Ejemplo n.º 5
0
 private void saveCredentials()
 {
     if (_currentState != null)
     {
         _persistentStore.Put(AK_KEY, _currentState.Credentials.AccessKey);
         _persistentStore.Put(SK_KEY, _currentState.Credentials.SecretKey);
         _persistentStore.Put(ST_KEY, _currentState.Credentials.Token);
         _persistentStore.Put(EXP_KEY, _currentState.Expiration.Ticks.ToString());
         _persistentStore.Put(IP_KEY, IdentityProvider.IdentityPoolId);
         _persistentStore.Put(ID_KEY, IdentityProvider.GetCurrentIdentityId());
         AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "CachingCognitoAWSCredentials", "Saved credentials to LocalStorage");
     }
 }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.ClientContextConfig"/> class.
        /// </summary>
        /// <param name="appTitle">App title -  The title of your app. For example, My App.</param>
        /// <param name="appVersionName">App version name - The version of your app. For example, V2.0.</param>
        /// <param name="appVersionCode">App version code - The version code for your app. For example, 3.</param>
        /// <param name="appPackageName">App package name - The name of your package. For example, com.example.my_app.</param>
        /// <param name="appId">App identifier - AWS Mobile Analytics App ID corresponding to your App</param>
        public ClientContextConfig(string appTitle, string appVersionName, string appVersionCode, string appPackageName, string appId)
        {
            if (string.IsNullOrEmpty(appTitle))
            {
                throw new ArgumentNullException("appTitle");
            }

            if (string.IsNullOrEmpty(appVersionName))
            {
                throw new ArgumentNullException("appVersionName");
            }

            if (string.IsNullOrEmpty(appId))
            {
                throw new ArgumentNullException("appId");
            }

            if (string.IsNullOrEmpty(appPackageName))
            {
                throw new ArgumentNullException("appPackageName");
            }

            if (string.IsNullOrEmpty(appVersionCode))
            {
                throw new ArgumentNullException("appVersionCode");
            }

            this._appTitle       = appTitle;
            this._appVersionName = appVersionName;
            this._appVersionCode = appVersionCode;
            this._appPackageName = appPackageName;
            this._appId          = appId;

            _kvStore  = new PlayerPreferenceKVStore();
            _clientId = _kvStore.Get(APP_CLIENT_ID_KEY);
            if (string.IsNullOrEmpty(_clientId))
            {
                _clientId = Guid.NewGuid().ToString();
                _kvStore.Put(APP_CLIENT_ID_KEY, _clientId);
            }
        }
Ejemplo n.º 7
0
 public void SetValue(string key, string value, ApplicationSettingsMode mode)
 {
     kvStore.Put(key, value);
 }