gpt4 book ai didi

ios - 如何使我的 iOS 应用程序安全地与 AWS S3 一起工作

转载 作者:行者123 更新时间:2023-11-28 08:52:28 27 4
gpt4 key购买 nike

我真的需要帮助,因为我整天都在战斗,但没有结果。我在 AWS S3 上有文件,我想通过 url 获取这些文件。我有读取此文件的 iOS 应用程序,一切正常。但我不会保护我的文件,所以要增加安全性,此后我遇到了很多麻烦。所以,我做了什么:

我添加了存储桶策略:

{
"Version": "2012-10-17",
"Id": "Policy1448129771756",
"Statement": [
{
"Sid": "Stmt1448129767926",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::646483417075:role/Cognito_MyAppAuth_Role"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my.files.info/*"
}
]
}

我创建了 Cognito Identity Pool,它为我生成了代码:

然后初始化凭据提供程序:

// Initialize the Amazon Cognito credentials provider  

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc]
initWithRegionType:AWSRegionUSEast1
identityPoolId:@"us-east-1:6f261e92-dca3-xxxxx-xxxxxxx-xxxxxxxxx"];

AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

我在 Swift 上写,所以我重写了这段代码:

let awsCognitoCredentialsProvider: AWSCognitoCredentialsProvider
let configuration: AWSServiceConfiguration

self.awsCognitoCredentialsProvider = AWSCognitoCredentialsProvider(regionType: AWSRegionType.USEast1,
identityPoolId: "us-east-1:6f261e92-dca3-xxxxx-xxxxx-xxxxxxxxxxxx")

self.configuration = AWSServiceConfiguration(region: AWSRegionType.USEast1, credentialsProvider: self.awsCognitoCredentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = self.configuration

它可以正常工作,但我在 AWS Cognito 控制台中看不到某些身份。我找到了很多代码示例,但它们都和我的一样。谁能帮帮我!

最佳答案

您是否使用 Cognito 进行了 API 调用?除非您这样做,否则它不会创建 id/get 凭据。请参阅 Cognito docs 中有关获取 Cognito id 的部分.这将创建 id 或给你一个错误。

关于ios - 如何使我的 iOS 应用程序安全地与 AWS S3 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33847937/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com