我一直在尝试为我的用户池用户生成这个“身份 ID”以访问 AWS 资源。但是没有成功。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
//user pool configuration
let serviceConfiguration = AWSServiceConfiguration(
region: AWSRegionType.USWest2,
credentialsProvider: nil)
let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: K.COGNITO_USER_POOL_APP_CLIENT_ID, clientSecret: K.COGNITO_USER_POOL_APP_CLIENT_SECRET, poolId: K.COGNITO_USER_POOL_ID)
//create a pool
AWSCognitoIdentityUserPool.registerCognitoIdentityUserPoolWithConfiguration(serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: "UserPool")
self.pool = AWSCognitoIdentityUserPool(forKey: "UserPool")
self.credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USWest2, identityPoolId: K.IDENTITY_POOL_ID, identityProviderManager: self.pool!)
let configuration = AWSServiceConfiguration(region: AWSRegionType.USWest2, credentialsProvider: self.credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
self.pool!.delegate = self
self.user = self.pool!.currentUser()
return true
}
这就是 Integrating User pool with Cognito(Swift) Documentation. 中给出的全部内容
虽然 Android 代码说在登录映射中传递“idToken”和用户池 url,但在 swift 代码中没有提到这样的事情。
到目前为止,在用户登录应用程序后,我在 Xcode 的日志窗口中获得了“AccessToken”和“IdToken”。
我还需要做什么才能获得经过验证的身份?如果我做错了,请纠正我。谢谢。
最佳答案
您是对的,该文档对身份池和用户池以及集成它们并没有多大帮助。
我的建议是使用 AWS Mobile Hub,而不是依赖于其他文档或示例。如果您使用该站点,它将下载一个完整的 Swift Xcode 项目,该项目正确地集成了用户池和另一个身份提供者(Google 或 Facebook)。用户池集成是移动中心的一项新功能。
此外,移动中心有一个很好的下载应用程序架构,将身份管理与登录管理分开。
但是如果你想继续使用文档来解决这个问题,下面的注释集应该会有所帮助。加上以下要点。
1) 如果您使用 SDK,则无需管理代币,SDK 会为您保留和交换代币。
2) 您所要做的就是正确配置您的用户池,正确配置您的 IAM,并调用一小段 SDK 调用(如下所述)。移动中心所做的一件很棒的事情就是让所有的事情都适合你一次,让你在学习的过程中修改和发展它。
3) 简短的调用顺序是: - 创建一个用户池 - 创建一个身份池 - 使用户池成为您的服务配置的 identityProviderManager (注意:你已经完成了上面的所有操作,所以你只需要执行以下步骤) - 执行获取身份 API 调用(这是在您执行“获取 session ”SDK 调用时完成的。 - 执行 GetCredentialsForIdentity API 调用(这是在您执行“凭据”SDK 调用时完成的)
届时,您将拥有凭据并能够根据您的登录(已验证)状态以及 IAM 中的任何相关规则访问 AWS 服务。
这些注释中有一个(我认为)有用的解释:notes on using cognito and user pools
在该存储库中还有一个用户池与身份池一起工作的示例,包括注册、忘记密码等,并且包括进行身份合并的能力。
(Mobile Hub 中的新用户池代码现在可以很好地完成其中的一些工作(截至 4 天前他们添加用户池代码时),但尚未进行身份合并。
希望对你有帮助
关于ios - AWS Cognito Authenticated Credentials IOS Swift 2.3 - 3(集成用户池和身份池),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40543212/