コード例 #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            try
            {
                CognitoHelper cognitoHelper = new CognitoHelper();
                cognitoUser = await cognitoHelper.ValidateUser(txtusername.Text, txtpassword.Text);

                MessageBox.Show("Login successfully");
                Console.WriteLine(cognitoUser.Username);

                CognitoAWSCredentials credentials = cognitoUser.GetCognitoAWSCredentials(ConfigurationManager.AppSettings["FED_POOL_id"], new AppConfigAWSRegion().Region);
                StringBuilder         tokens      = new StringBuilder();

                tokens.Append("================Cognito Credentails==================\n");
                tokens.Append("Access Key - " + credentials.GetCredentials().AccessKey);
                tokens.Append("\nSecret - " + credentials.GetCredentials().SecretKey);
                tokens.Append("\nSession Token - " + credentials.GetCredentials().Token);
                tokens.Append("\nUseToken Token - " + credentials.GetCredentials().UseToken.ToString());
                Console.WriteLine(tokens.ToString());
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
                MessageBox.Show("Unable to validate the username and password");
            }
        }
コード例 #2
0
        public async Task <string> GetS3BucketsAsync(CognitoUser user)
        {
            CognitoAWSCredentials credentials =
                user.GetCognitoAWSCredentials(FED_POOL_ID, new AppConfigAWSRegion().Region);
            StringBuilder bucketlist = new StringBuilder();

            bucketlist.Append("================Cognito Credentails==================\n");
            bucketlist.Append("Access Key - " + credentials.GetCredentials().AccessKey);
            bucketlist.Append("\nSecret - " + credentials.GetCredentials().SecretKey);
            bucketlist.Append("\nSession Token - " + credentials.GetCredentials().Token);

            bucketlist.Append("\n================User Buckets==================\n");

            using (var client = new AmazonS3Client(credentials))
            {
                ListBucketsResponse response =
                    await client.ListBucketsAsync(new ListBucketsRequest()).ConfigureAwait(false);

                foreach (S3Bucket bucket in response.Buckets)
                {
                    bucketlist.Append(bucket.BucketName);

                    bucketlist.Append("\n");
                }
            }
            Console.WriteLine(bucketlist.ToString());
            return(bucketlist.ToString());
        }
コード例 #3
0
        public void AuthenticatedCredentialsTest()
        {
            CognitoAWSCredentials authCred = AuthCredentials;

            string identityId = authCred.GetIdentityId();

            Utils.AssertStringIsNotNullOrEmpty(identityId);
            ImmutableCredentials cred = authCred.GetCredentials();

            Utils.AssertFalse(cred == null);
        }
コード例 #4
0
ファイル: SyncManager.cs プロジェクト: eangelov/aws-sdk-net-1
        //[TestMethod]
        //[TestCategory("SyncManager")]
        public void AuthenticatedCredentialsTest()
        {
            CognitoAWSCredentials authCred = AuthCredentials;

            string identityId = authCred.GetIdentityId();

            Assert.IsTrue(!string.IsNullOrEmpty(identityId));
            ImmutableCredentials cred = authCred.GetCredentials();

            Assert.IsNotNull(cred);
        }
コード例 #5
0
    // Called by Unity when the Gameobject is created
    void Start()
    {
        FindObjectOfType <UIManager>().SetTextBox("Setting up Client..");

        // Get an identity and connect to server
        CognitoAWSCredentials credentials = new CognitoAWSCredentials(
            MatchmakingClient.identityPoolID,
            MatchmakingClient.region);

        Client.cognitoCredentials = credentials.GetCredentials();
        Debug.Log("Got credentials: " + Client.cognitoCredentials.AccessKey + "," + Client.cognitoCredentials.SecretKey);

        StartCoroutine(ConnectToServer());
    }
コード例 #6
0
    // Called when Start game button is clicked
    void StartGame()
    {
        if (!this.gameStartRequested)
        {
            this.startGameButton.gameObject.SetActive(false);
            this.gameStartRequested = true;

            FindObjectOfType <UIManager>().SetTextBox("Setting up Client..");

            // Get the Region enum from the string value
            this.region = Amazon.RegionEndpoint.GetBySystemName(regionString);
            Debug.Log("My Region endpoint: " + this.region);

            // Check if we have stored an identity and request credentials for that existing identity
            Client.cognitoID = PlayerPrefs.GetString("CognitoID", null);
            if (Client.cognitoID != null && Client.cognitoID != "")
            {
                Debug.Log("Requesting credentials for existing identity: " + Client.cognitoID);
                var response = Task.Run(() => GetCredentialsForExistingIdentity(Client.cognitoID));
                response.Wait(5000);
                Client.cognitoID          = response.Result.IdentityId;
                Client.cognitoCredentials = new Amazon.Runtime.ImmutableCredentials(response.Result.Credentials.AccessKeyId, response.Result.Credentials.SecretKey, response.Result.Credentials.SessionToken);
            }
            // Else get a new identity
            else
            {
                Debug.Log("Requesting a new playeridentity as none stored yet.");
                CognitoAWSCredentials credentials = new CognitoAWSCredentials(
                    this.identityPoolID,
                    this.region);
                Client.cognitoCredentials = credentials.GetCredentials();
                Client.cognitoID          = credentials.GetIdentityId();
                Debug.Log("Got Cognito ID: " + credentials.GetIdentityId());

                // Store to player prefs and save for future games
                PlayerPrefs.SetString("CognitoID", Client.cognitoID);
                PlayerPrefs.Save();
            }

            // Get latencies to regions
            this.MeasureLatencies();

            // Connect to the server now that we have our identity, credendtials and latencies
            StartCoroutine(ConnectToServer());
        }
    }
コード例 #7
0
ファイル: AWS_MQTT.cs プロジェクト: Hosemans/airconcontrol
        public void LoginUser()
        {
            try
            {
                AmazonCognitoIdentityProviderClient _provider = new AmazonCognitoIdentityProviderClient((AWSCredentials) new AnonymousAWSCredentials(), RegionEndpoint.APSoutheast2);
                CognitoUserPool pool        = new CognitoUserPool(AWS_USER_POOL_ID, AWS_CLIENT_ID, _provider);
                CognitoUser     cognitoUser = new CognitoUser(AWS_Username, AWS_CLIENT_ID, pool, _provider);
                cognitoUser.StartWithSrpAuthAsync(new InitiateSrpAuthRequest()
                {
                    Password = AWS_Password
                }).Wait();
                COGNITO_USER = cognitoUser;

                COGNITO_AWS_CREDENTIALS = COGNITO_USER.GetCognitoAWSCredentials(AWS_POOL_ID, AWS_REGION_ENDPOINT);
                AWS_CREDENTIALS         = COGNITO_AWS_CREDENTIALS.GetCredentials();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
        public async Task <bool> getCredentials()
        {
            var credentials = new CognitoAWSCredentials(Statics.identityPoolID,
                                                        RegionEndpoint.EUWest2);

            var providername =
                $"cognito-idp.{RegionEndpoint.EUWest2.SystemName}.amazonaws.com/{Statics.poolID}";

            Console.WriteLine(providername);
            credentials.AddLogin(providername, Statics.id_token);

            var creds = credentials.GetCredentials();

            Statics.creds       = creds;
            Statics.credentials = credentials;

            Console.WriteLine("log in id::" + credentials);
            Console.WriteLine(creds);

            return(true);
        }
コード例 #9
0
        public async Task <IActionResult> AssumeRoleWithCognitoAsync()
        {
            if (!this.HttpContext.User.Identity.IsAuthenticated)
            {
                return(new OkObjectResult("you have to sign in to access AWS resources"));
            }

            try
            {
                // Initialize the Amazon Cognito credentials provider
                //CognitoAWSCredentials credentials = new CognitoAWSCredentials(
                //    "us-east-2:c6e1e652-eb33-4daa-a04e-9cb0418a92cc", // Identity pool ID
                //    RegionEndpoint.USEast2 // Region
                //);
                var credentials = new CognitoAWSCredentials(
                    accountId: "628654266155",
                    identityPoolId: "us-east-2:c6e1e652-eb33-4daa-a04e-9cb0418a92cc",
                    unAuthRoleArn: null,
                    authRoleArn: "arn:aws:iam::628654266155:role/acme_app_access_s3",
                    region: RegionEndpoint.USEast2
                    );

                credentials.AddLogin("dev-220949.okta.com", GetOktaTokenMiddleware.OktaToken);

                var creds = credentials.GetCredentials();

                var s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast2);

                return(await this.ObjectFromBucket(s3Client));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
コード例 #10
0
        public ActionResult Index()
        {
            //works nicely
            var currentClaims = this.User.Claims;

            var kk = _service.AuthenticateAsync(this.HttpContext, IdentityConstants.ApplicationScheme).Result;
            CognitoAWSCredentials cogCred = new CognitoAWSCredentials("ap-southeast-2:67c062aa-1a19-49da-b30c-8a5b0f2287f2", Amazon.RegionEndpoint.APSoutheast2);

            string provider = "cognito-idp.ap-southeast-2.amazonaws.com/ap-southeast-2_FFDK2FLGl";
            // cogCred.AddLogin(provider, kk.Properties.Items[".Token.id_token"]);


            ImmutableCredentials tempCred = cogCred.GetCredentials();

            string accessKey = tempCred.AccessKey;
            string secretKey = tempCred.SecretKey;


            IAmazonDynamoDB db = new AmazonDynamoDBClient(cogCred, Amazon.RegionEndpoint.APSoutheast2);



            string            tableName = "Animals";
            Table             animalTbl = Table.LoadTable(db, tableName);
            List <AnimalInfo> result    = new List <AnimalInfo>();


            var singleItem = animalTbl.GetItemAsync("ap-southeast-2:7926aa93-dd73-482d-83fd-7bc2efac7cd6").Result;

            if (singleItem != null)
            {
            }
            AnimalInfo info = new AnimalInfo();

            info.AnimalId = singleItem["AnimalId"];
            info.Name     = singleItem["Name"];
            info.Age      = singleItem["Age"].AsInt();
            info.Breed    = singleItem["Breed"];
            result.Add(info);


            //ScanFilter scanFilter = new ScanFilter();
            //scanFilter.AddCondition("AnimalId", ScanOperator.Contains, "07738fa2-b0ee-4799-be82-f9088855df80");
            //Search search = animalTbl.Scan(scanFilter);
            //do
            //{
            //    var items = search.GetNextSetAsync().Result;
            //    foreach (var i in items)
            //    {
            //        AnimalInfo info = new AnimalInfo();
            //        info.AnimalId = i["AnimalId"];
            //        info.Name = i["Name"];
            //        info.Age = i["Age"].AsInt();
            //        info.Breed = i["Breed"];
            //        result.Add(info);
            //    }
            //} while (!search.IsDone);


            return(View(result));
        }