2016-11-11 125 views
1

我一直在试图为我的用户池用户访问AWS资源生成此“身份标识”。但一直不成功。AWS Cognito认证凭证IOS Swift 2.3 - 3(集成用户池和身份池)

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”。

我需要做些什么才能获得身份验证身份?纠正我,如果我做错了..谢谢。

回答

1

你是对的,这些文档对身份池和用户池并没有太大的帮助,并且使它们集成在一起。

我的建议是,而不是依赖其他文档或示例,使用AWS Mobile Hub。如果您使用该站点,它将下载一个完整的Swift Xcode项目,该项目可以正确完成用户池和另一个身份提供程序(Google或Facebook)的集成。用户池集成是移动集线器的一项新功能。

此外,移动中心有一个很好的下载应用程序体系结构,将身份管理与登录管理分开。

但是,如果你想继续通过这个使用文档记录下来,下面的一组备注应该有所帮助。加上以下几点要点。

1)如果你使用的SDK你没有管理令牌,该SDK得到保持和你交换令牌。

2)所有你需要做的是正确地配置您的用户池,正确地配置您的IAM,并调用SDK调用的短序列(概述如下)。移动中心所做的一件伟大的事情就是一次为你准备好所有的东西,让你在学习的时候修改和发展它。

3)调用的短序列是: - 使用户池 - 做一个身份池 - 使用户池identityProviderManager为您服务配置 (注:你已经做了一切之上,因此所有你需要的是执行以下步骤) - 执行get身份API调用(这样做,当你做“获取会话” SDK调用 - 执行GetCredentialsForIdentity API调用(当你这样做的“资格证书”这样做SDK调用)

在这一点上,你将有凭据,并访问基于您的登录(认证)状态下,AWS服务的能力d IAM中的任何相关规则。

有一个(我认为)在这些笔记有帮助的说明:在库notes on using cognito and user pools

另外,也有与身份库的用户池的共同努力,包括注册一个例子,忘记密码等,并包括能力做身份合并。(Mobile Hub中的新用户池代码现在可以很好地完成一些操作(截至4天前添加用户池代码时),但尚未完成身份合并)。

希望这会有所帮助

相关问题