コード例 #1
0
        public void CredentialsTests()
        {
            CognitoAWSCredentials cred1 = new CognitoAWSCredentials(poolId, ActualEndpoint);
            string         id1 = null, id2 = null, id3 = null;
            AutoResetEvent ars = new AutoResetEvent(false);

            cred1.GetIdentityIdAsync((result) =>
            {
                id1 = result.Response;
                ars.Set();
            }, new Amazon.Runtime.AsyncOptions()
            {
                ExecuteCallbackOnMainThread = false
            });

            ars.WaitOne();
            Utils.AssertFalse(string.IsNullOrEmpty(id1));
            var cred2 = new CognitoAWSCredentials(poolId, ActualEndpoint);

            cred2.GetIdentityIdAsync((result) =>
            {
                id2 = result.Response;
                ars.Set();
            }, new Amazon.Runtime.AsyncOptions()
            {
                ExecuteCallbackOnMainThread = false
            });
            ars.WaitOne();
            Utils.AssertFalse(string.IsNullOrEmpty(id2));

            Assert.AreEqual(id1, id2);

            cred1.Clear();

            Utils.AssertStringIsNullOrEmpty(cred1.GetCachedIdentityId());

            cred1.GetIdentityIdAsync((result) =>
            {
                id3 = result.Response;
                ars.Set();
            }, new Amazon.Runtime.AsyncOptions()
            {
                ExecuteCallbackOnMainThread = false
            });

            ars.WaitOne();

            Assert.IsNotNull(id3);

            Assert.AreNotEqual(id1, id3);

            cred1.Clear();
            cred2.Clear();
        }
コード例 #2
0
        /*
         * Initialization.
         */

        public static void Initialize(string poolId)
        {
            if (Initializing)
            {
                _log.Error("Already initializing");
                return;
            }

            if (Initialized)
            {
                _log.Error("Already initialized");
                return;
            }

            _log.Debug("Initializing");

            Initializing = true;

            _poolId   = poolId;
            _instance = new GameObject("BitszerAuctionHouse").AddComponent <AuctionHouse>();

            UnityInitializer.AttachToGameObject(_instance.gameObject);

            AWSConfigs.HttpClient          = AWSConfigs.HttpClientOption.UnityWebRequest;
            AWSConfigs.LoggingConfig.LogTo = LoggingOptions.None;

            _credentials = new CognitoAWSCredentials(_poolId, RegionEndpoint);
            _credentials.GetIdentityIdAsync(OnIdentityReceived);

            _syncManager = new CognitoSyncManager(_credentials, RegionEndpoint);
        }
コード例 #3
0
    // Use this for initialization
    void Start()
    {
        // Load all sprites in the Kenney.nl resource folder.
        allSprites = Resources.LoadAll <Sprite>("Kenney.nl");

        selectedHair  = selectedHairImage.overrideSprite.name;
        selectedFace  = selectedFaceImage.overrideSprite.name;
        selectedBody  = selectedBodyImage.overrideSprite.name;
        selectedShirt = selectedShirtImage.overrideSprite.name;
        selectedPants = selectedPantsImage.overrideSprite.name;
        selectedShoes = selectedShoesImage.overrideSprite.name;

        // Setup our credentials which will use our Cognito identity pool to hand us short-term session credentials,
        // giving us access to what we have provided access to with our IAM role policies, in this case, access to our
        // DynamoDB table.
        credentials = new CognitoAWSCredentials(cognitoIdentityPoolString, RegionEndpoint.USEast1);
        credentials.GetIdentityIdAsync(delegate(AmazonCognitoIdentityResult <string> result)
        {
            if (result.Exception != null)
            {
                Debug.LogError("exception hit: " + result.Exception.Message);
            }

            // Create a DynamoDB client, passing in our credentials from Cognito.
            var ddbClient = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1);

            resultText.text += ("\n*** Retrieving table information ***\n");

            // Create a DescribeTableRequest to get information about our table, and ensure we can access it.
            var request = new DescribeTableRequest
            {
                TableName = @"CharacterCreator"
            };

            ddbClient.DescribeTableAsync(request, (ddbresult) =>
            {
                if (result.Exception != null)
                {
                    resultText.text += result.Exception.Message;
                    Debug.Log(result.Exception);
                    return;
                }

                var response = ddbresult.Response;

                // Debug information
                TableDescription description = response.Table;
                resultText.text += ("Name: " + description.TableName + "\n");
                resultText.text += ("# of items: " + description.ItemCount + "\n");
                resultText.text += ("Provision Throughput (reads/sec): " + description.ProvisionedThroughput.ReadCapacityUnits + "\n");
                resultText.text += ("Provision Throughput (reads/sec): " + description.ProvisionedThroughput.WriteCapacityUnits + "\n");
            }, null);

            // Set our _client field to the dynamoDB client.
            _client = ddbClient;

            // Fetch any stored characters from the DB
            FetchAllCharactersFromAWS();
        });
    }
コード例 #4
0
 /// <summary>
 /// Retrieve an identity string from Cognito, using Facebook for
 /// authentication if possible.
 /// </summary>
 /// <param name="callback">Callback function, callback(error, identity).</param>
 public void UpdateIdentity()
 {
     loading = true;
     credentials.GetIdentityIdAsync((AmazonCognitoIdentityResult <string> result) => {
         Debug.Log("GetIdentity result: '" + result.Response + "'");
         myIdentity = result.Response;
         loading    = false;
     });
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: afukuma/CognitoDesktop
        private async void BtnSignIn_ClickAsync(object sender, EventArgs e)
        {
            try
            {
                AmazonCognitoIdentityProviderClient provider =
                    new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), wwRegion);
                CognitoUserPool        userPool    = new CognitoUserPool(wwUserPoolID, wwAppClientID, provider);
                CognitoUser            user        = new CognitoUser(txtID.Text, wwAppClientID, userPool, provider);
                InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest()
                {
                    Password = txtPass.Text
                };

                AuthFlowResponse authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);

                string accessToken = authResponse.AuthenticationResult.AccessToken;
                string idToken     = authResponse.AuthenticationResult.IdToken;

                // Amazon Cognito 認証情報プロバイダーを初期化します
                CognitoAWSCredentials credentials = new CognitoAWSCredentials(
                    wwIdPoolID, // ID プールの ID
                    wwRegion    // リージョン
                    );

                credentials.AddLogin("cognito-idp.us-east-1.amazonaws.com/" + wwUserPoolID, idToken); // the raw token
                //↓おまじない
                string hoge = await credentials.GetIdentityIdAsync();

                using (var client = new AmazonS3Client(credentials, wwRegion))
                {
                    var listObjectRequest = new ListObjectsRequest();
                    listObjectRequest.BucketName = wwS3BucketName;
                    var response = await client.ListObjectsAsync(listObjectRequest);

                    //ここでオブジェクトがとれる
                    ;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #6
0
        public void MultipleIdentityPoolTests()
        {
            CreatePool();
            Utils.AssertTrue(allPoolIds.Count == 2);
            var pool1 = allPoolIds[0];
            var pool2 = allPoolIds[1];

            var    cred1 = new CognitoAWSCredentials(pool1, ActualEndpoint);
            var    cred2 = new CognitoAWSCredentials(pool2, ActualEndpoint);
            string id1 = null, id2 = null;

            AutoResetEvent ars = new AutoResetEvent(false);

            cred1.GetIdentityIdAsync((result) =>
            {
                id1 = result.Response;
                ars.Set();
            }, new Amazon.Runtime.AsyncOptions()
            {
                ExecuteCallbackOnMainThread = false
            });
            ars.WaitOne();

            Utils.AssertFalse(string.IsNullOrEmpty(id1));
            cred2.GetIdentityIdAsync((result) =>
            {
                id2 = result.Response;
                ars.Set();
            }, new Amazon.Runtime.AsyncOptions()
            {
                ExecuteCallbackOnMainThread = false
            });

            ars.WaitOne();
            Utils.AssertFalse(string.IsNullOrEmpty(id2));
            Assert.AreNotEqual(id1, id2);
            cred1.Clear();
            Utils.AssertStringIsNullOrEmpty(cred1.GetCachedIdentityId());

            cred2.Clear();
            cred1.Clear();
        }
コード例 #7
0
        public virtual async Task <string> GetIdentityToken()
        {
            if (CognitoUser == null)
            {
                return(null); // Need to authenticate user first!
            }
            if (!string.IsNullOrEmpty(identityPoolId))
            { // Using Identity Pools
                //var credentials = new CognitoAWSCredentials(IdentityPoolId, RegionEndpoint);
                CognitoAWSCredentials credentials = CognitoUser.GetCognitoAWSCredentials(identityPoolId, regionEndpoint);

                try
                {
                    var IpIdentity = await credentials.GetIdentityIdAsync();

                    Debug.WriteLine($" IpIdentity {IpIdentity}");
                    return(IpIdentity);
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"{e.Message}");
                    return(null);
                }
            }

            // Using UserPools directly
            if (CognitoUser.SessionTokens.IsValid())
            {
                return(CognitoUser.SessionTokens.IdToken);
            }
            if (await RefreshTokenAsync())
            {
                return(CognitoUser.SessionTokens.IdToken);
            }
            return(null);
        }