Example #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="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="cibClient">Preconfigured Cognito Identity client to make requests with</param>
        /// <param name="stsClient">>Preconfigured STS client to make requests with</param>
        public CognitoAWSCredentials(string unAuthRoleArn, string authRoleArn,
                                     AbstractCognitoIdentityProvider idClient, IAmazonSecurityTokenService stsClient)
        {
            if (string.IsNullOrEmpty(unAuthRoleArn) && string.IsNullOrEmpty(authRoleArn))
            {
                throw new InvalidOperationException("At least one of unAuthRoleArn or authRoleArn must be specified");
            }
            if (idClient == null)
            {
                throw new ArgumentNullException("idClient");
            }
            if (stsClient == null)
            {
                throw new ArgumentNullException("stsClient");
            }

            UnAuthRoleArn    = unAuthRoleArn;
            AuthRoleArn      = authRoleArn;
            IdentityProvider = idClient;
            sts = stsClient;
        }
Example #2
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="cibClient">Preconfigured Cognito Identity client to make requests with</param>
        /// <param name="stsClient">Preconfigured STS client to make requests with</param>
        public CognitoAWSCredentials(string unAuthRoleArn, string authRoleArn,
                                     AbstractCognitoIdentityProvider idClient, IAmazonSecurityTokenService stsClient)
        {
            if (idClient == null)
            {
                throw new ArgumentNullException("idClient");
            }

            UnAuthRoleArn    = unAuthRoleArn;
            AuthRoleArn      = authRoleArn;
            IdentityProvider = idClient;
            sts = stsClient;

                        #if UNITY_WEBPLAYER
            _persistentStore = new InMemoryKVStore();
                        #else
            _persistentStore = new SQLiteKVStore();
                        #endif

            //Load cached credentials
            string cachedIdentity = _persistentStore.Get(namespacedKey(ID_KEY));
            if (string.IsNullOrEmpty(cachedIdentity))
            {
                //Try to recover unamespaced identities stored by old versions of the SDK
                cachedIdentity = _persistentStore.Get(ID_KEY);
            }
            if (!string.IsNullOrEmpty(cachedIdentity))
            {
                IdentityProvider.UpdateIdentity(cachedIdentity);
                loadCachedCredentials();
            }

            //Register Identity Changed Listener to update the cache
            IdentityProvider.IdentityChangedEvent += delegate(object sender, IdentityChangedArgs e)
            {
                saveCredentials();
                AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "CognitoAWSCredentials", "Saved identityID to LocalStorage");
            };
        }
Example #3
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="cibClient">Preconfigured Cognito Identity client to make requests with</param>
 /// <param name="stsClient">>Preconfigured STS client to make requests with</param>
 public CachingCognitoAWSCredentials(string unAuthRoleArn, string authRoleArn,
                                     AbstractCognitoIdentityProvider idClient, IAmazonSecurityTokenService stsClient)
     : base(unAuthRoleArn, authRoleArn, idClient, stsClient)
 {
 }