简体   繁体   English

发送带有S3存储桶访问密钥的MFA令牌,使用c#上传文件

[英]Send MFA token with access key for S3 bucket, file upload using c#

I am trying to add MFA (Multi Factor Authentication) in my application, where i am going to store object in aws S3 bucket. 我正在尝试在我的应用程序中添加MFA(多重身份验证),我将在aws S3存储桶中存储对象。 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#. 我查看了AWS文档,但在C#中以编程方式向AWS发送任何请求时,找不到任何可以传递MFA tokedn的内容。

Here is my working code snippet without MFA, 这是我没有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. 我希望在上面的代码中添加MFA身份验证令牌。

The TOTP from an MFA token isn't passed directly with the request. 来自MFA令牌的TOTP不直接与请求一起传递。

Instead, you first make a call to Security Token Service (STS) where you essentially "exchange" your current credentials and MFA info for a set of temporary credentials that are used to authenticate subsequent requests. 相反,您首先调用安全令牌服务(STS),其中您实际上“交换”当前凭据和MFA信息,以获取用于验证后续请求的一组临时凭证。

The user calls one of the AWS STS API operations that support the MFA parameters, AssumeRole or GetSessionToken , depending on the scenario for MFA protection, as explained later. 用户来电支持MFA参数时,AWS STS API操作的一个AssumeRoleGetSessionToken ,这取决于MFA保护的情况下,后面会解释。 As part of the call, the user includes the device identifier for the device that's associated with the user. 作为呼叫的一部分,用户包括与用户相关联的设备的设备标识符。 The user also includes the time-based one-time password (TOTP) that the device generates. 用户还包括设备生成的基于时间的一次性密码(TOTP)。 In either case, the user gets back temporary security credentials that the user can then use to make additional requests to AWS. 在任何一种情况下,用户都会获得临时安全凭证,然后用户可以使用该凭证向AWS发出其他请求。

https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_configure-api-require.html https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_configure-api-require.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用c#将大型文件从一个S3存储桶复制到另一个S3存储桶 - Copy Large file from one S3 bucket to another S3 Bucket using c# 使用c#写入Amazon s3存储桶上的文件 - Writing to a file on Amazon s3 bucket using c# 使用C#将文件添加到Amazon S3上的存储桶 - Adding a file to a bucket on Amazon S3 using C# 使用 C# 在 S3 存储桶中获取最近的文件 - Get recent file in S3 bucket using C# -AWS C#.Net Core-如何将.jpg图像上传到S3存储桶而不将其另存为文件 - -AWS C# .Net Core- How to upload a .jpg image to S3 bucket without saving it as a file Wowza-使用c#/ Rest API将记录上传到AWS S3存储桶 - Wowza - upload recording to AWS S3 bucket using c#/Rest API C# 如何使用亚马逊 s3 存储桶将图像从本地上传到云服务器 - C# How to Upload image from local to cloud server using amazon s3 bucket 需要使用c#实现AWS S3存储桶文件上传。 文件大小不受限制 - Need to implementation AWS S3 Bucket file upload using c#. Whereas file size is not limit 如何解析 AWS S3 路径 (s3://<bucket name> /<key> ) 在 C# 中使用 AWSSDK.S3 以获取存储桶名称和密钥 - How to parse the AWS S3 Path (s3://<bucket name>/<key>) using the AWSSDK.S3 in C# in order to get the bucket name & key 使用 C# 从 s3 存储桶下载文件 - download files from s3 bucket using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM