/// <summary> /// Creates an insance of CognitoSyncStorage. /// </summary> /// <param name="cognitoCredentials"><see cref="Amazon.CognitoIdentity.CognitoAWSCredentials"/></param> /// <param name="config"><see cref="Amazon.CognitoSync.AmazonCognitoSyncConfig"/></param> public CognitoSyncStorage(CognitoAWSCredentials cognitoCredentials, AmazonCognitoSyncConfig config) { if (cognitoCredentials == null) { throw new ArgumentNullException("cognitoCredentials"); } this.identityPoolId = cognitoCredentials.IdentityPoolId; this.cognitoCredentials = cognitoCredentials; this.client = new AmazonCognitoSyncClient(cognitoCredentials, config); }
public CognitoSyncStorage(CognitoAWSCredentials cognitoCredentials, AmazonCognitoSyncConfig config) { if (cognitoCredentials == null) { throw new ArgumentNullException("cognitoCredentials"); } this.identityPoolId = cognitoCredentials.IdentityPoolId; this.cognitoCredentials = cognitoCredentials; this.client = new AmazonCognitoSyncClient(cognitoCredentials, config); }
protected IAmazonCognitoSync CreateClient(AWSCredentials credentials, RegionEndpoint region) { var config = new AmazonCognitoSyncConfig { RegionEndpoint = region }; Amazon.PowerShell.Utils.Common.PopulateConfig(this, config); this.CustomizeClientConfig(config); var client = new AmazonCognitoSyncClient(credentials, config); client.BeforeRequestEvent += RequestEventHandler; client.AfterResponseEvent += ResponseEventHandler; return(client); }
public static void Main(string[] args) { //Set up CognitoAWSCredentials CognitoAWSCredentials credentials = new CognitoAWSCredentials( accountId, // Account number identityPoolId, // Identity pool ID unAuthRoleArn, // Role for unauthenticated users null, // Role for authenticated users, not set region); using (var s3Client = new AmazonS3Client(credentials)) { s3Client.ListBuckets(); } //Use AWS as an Unautheticated User CognitoAWSCredentials credentials = new CognitoAWSCredentials( accountId, identityPoolId, unAuthRoleArn, // Role for unauthenticated users authRoleArn, // Role for authenticated users region); using (var s3Client = new AmazonS3Client(credentials)) { // Initial use will be unauthenticated s3Client.ListBuckets(); // Authenticate user through Facebook string facebookToken = GetFacebookAuthToken(); // Add Facebook login to credentials. This clears the current AWS credentials // and retrieves new AWS credentials using the authenticated role. credentials.AddLogin("graph.facebook.com", facebookAccessToken); // This call is performed with the authenticated role and credentials s3Client.ListBuckets(); } // One more example CognitoAWSCredentials credentials = GetCognitoAWSCredentials(); // Log identity changes credentials.IdentityChangedEvent += (sender, args) => { Console.WriteLine("Identity changed: [{0}] => [{1}]", args.OldIdentityId, args.NewIdentityId); }; using (var syncClient = new AmazonCognitoSyncClient(credentials)) { var result = syncClient.ListRecords(new ListRecordsRequest { DatasetName = datasetName // No need to specify these properties //IdentityId = "...", //IdentityPoolId = "..." }); } }
private AwsDynamoDbHelper() //Made private for singleton { //****** Taken from https://us-east-2.console.aws.amazon.com/cognito/code/?region=us-east-2&pool=us-east-2:f4f90926-c251-456c-b82d-ac691a5a70e0. // Get AWS credentials. Taken from https://us-east-2.console.aws.amazon.com/cognito/code/?region=us-east-2&pool=us-east-2:f4f90926-c251-456c-b82d-ac691a5a70e0. _credentials = new CognitoAWSCredentials( //"us-east-2:f4f90926-c251-456c-b82d-ac691a5a70e0", // Identity pool ID //"us-east-2:fc497215-b4e7-48f6-b4b4-ae4618026857", // Identity pool ID for DynamoDbIdentityPool CodeConstants.AWS.IDENTITY_POOL_ID, RegionEndpoint.USEast2 // Region ); //****** Adapted from https://docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/getting-started-store-retrieve-data.html. _client = new AmazonDynamoDBClient(_credentials, RegionEndpoint.USEast2); _context = new DynamoDBContext(_client); //****** // Initialize the Cognito Sync client. Taken from https://us-east-2.console.aws.amazon.com/cognito/code/?region=us-east-2&pool=us-east-2:f4f90926-c251-456c-b82d-ac691a5a70e0. //CognitoSyncManager syncManager = new CognitoSyncManager( Amazon.CognitoSync.AmazonCognitoSyncClient syncClient = new AmazonCognitoSyncClient( //Found out this line through trial and error. _credentials, new AmazonCognitoSyncConfig { RegionEndpoint = RegionEndpoint.USEast2 // Region } ); //AmazonCognitoSyncConfig clientConfig = new AmazonCognitoSyncConfig //{ // RegionEndpoint = RegionEndpoint.USEast2 //}; //Amazon.CognitoSync.AmazonCognitoSyncClient syncClient = new AmazonCognitoSyncClient(credentials, clientConfig); // Create a record in a dataset and synchronize with the server. //Dataset dataset = syncClient. OpenOrCreateDataset("myDataset"); //dataset.OnSyncSuccess += SyncSuccessCallback; //dataset.Put("myKey", "myValue"); //dataset.SynchronizeAsync(); //****** //****** Adapted from https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetTableOperationsExample.html. //try //{ // SaveItemAsync(); // //CreateTableAsync("ExampleTable"); // //WaitUntilTableReadyAsync("ExmapleTable"); // //ListTables(100); // //GetTableInformation("ExmapleTable"); // //GetTableInformation("DynamoDBTest"); //} //catch (AmazonDynamoDBException e) //{ // _isStatusOk = false; // System.Diagnostics.Debug.WriteLine("Overall AmazonDynamoDBException = " + e.Message); //} //catch (AmazonServiceException e) //{ // _isStatusOk = false; // System.Diagnostics.Debug.WriteLine("Overall AmazonServiceException = " + e.Message); //} //catch (Exception e) //{ // _isStatusOk = false; // System.Diagnostics.Debug.WriteLine("Overall Exception = " + e.Message); //} ////****** //finally //{ // if(_isStatusOk) // System.Diagnostics.Debug.WriteLine("Overall status = OK"); // _isStatusOk = true; //} //******Adapted from https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItemsDocumentClasses.html. //Table table = Table.LoadTable(_client, "DynamoDBTest"); //****** //var currentTime = DateTime.Now; //****** Adapted from https://docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/getting-started-store-retrieve-data.html. //Item testItem = new Item() //{ // //Id = "1", // //SavedTimeStamp = DateTime.Now.ToString(CodeConstants.DateTime.TIMESTAMP_WITH_OFFSET), // Id = currentTime.ToString(CodeConstants.DateTime.TIMESTAMP_WITH_OFFSET_NO_SPACES_NO_SEPARATORS) + "#" + Guid.NewGuid().ToString(), // SavedTimeStamp = currentTime.ToString(CodeConstants.DateTime.TIMESTAMP_WITH_OFFSET), // Name = "Testing_AwsDynamoDbTestPage()" //}; //_context.SaveAsync(testItem); ////****** }