open-guides / og-aws

📙 Amazon Web Services — a practical guide
Creative Commons Attribution 4.0 International
35.64k stars 3.86k forks source link

Send MFA token with access key for S3 bucket, file upload using c# programmatically #696

Open RakeshAlajpur opened 5 years ago

RakeshAlajpur commented 5 years ago

I am trying to add MFA (Multi Factor Authentication) in my application, where i am going to store object in aws S3 bucket. I went through AWS documentation but could not find anything where we can pass MFA tokedn while sending any request to AWS programmatically in C#.

Here is my working code snippet without MFA,

var awsCredentials = new BasicAWSCredentials(accessKey, secretKey); _client = new AmazonS3Client(awsCredentials, Amazon.RegionEndpoint.USEast1);

var putRequest = new PutObjectRequest {

BucketName = ConfigurationManager.AppSettings["S3BucketName"], Key = fileName, FilePath = localFilePath, ContentType = "image/" + Path.GetExtension(fileName), CannedACL = S3CannedACL.PublicRead }; var req = JsonConvert.SerializeObject(putRequest);

I am expecting to add MFA authentication token to this above code.

Thanks,

paulwakeford commented 4 years ago

Best to ask this in the Slack group, @RakeshAlajpur.