AWS Cognito用户池与标识池集成

时间:2016-07-07 13:27:09

标签: ios swift amazon-web-services amazon-cognito

我正在尝试使用用户池和标识池为我的iOS应用程序实现登录/注册功能。我遇到的问题是我的用户池中的所有用户在凭据提供程序上调用getIdentityId时都会收到相同的标识池ID。我无法弄清楚如何解决这个问题。任何帮助将不胜感激。

App代理中的

代码:

var pool: AWSCognitoIdentityUserPool?
var credentialsProvider: AWSCognitoCredentialsProvider?
var dynamoMapper: AWSDynamoDBObjectMapper?

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)

AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = serviceConfiguration

let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "", clientSecret: "" , poolId: "")

AWSCognitoIdentityUserPool.registerCognitoIdentityUserPoolWithConfiguration(serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: "UserPool")

pool = AWSCognitoIdentityUserPool(forKey: "UserPool")

credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "", identityProviderManager: pool)

let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialsProvider)

AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

dynamoMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()   

return true
}
登录视图控制器中的

代码:

let user = pool!.getUser(self.email.text!)
user.getSession(self.email.text!, password: self.password.text!, validationData: nil, scopes: nil).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task: AWSTask) -> AnyObject? in

    if (task.error == nil) {

        credentialsProvider!.getIdentityId().continueWithBlock({ (task1: AWSTask) -> AnyObject? in
            if (task1.error != nil) {

                print("error on login")

            } else {

                print("succesful login")
            }
            return nil
        })


    } else {
        print("error")
    }
    return nil
})

0 个答案:

没有答案