1

Problem: I have two user pools in Cognito. Let's call them Pool A and B. I am able to authenticate a user to "Pool A" successfully.

I need to authenticate a user created by backend dynamically to "Pool B" from the client.

Docs I have read: * Amazon Amplify * Amazon Cognito * Amazon SDK for iOS * AWSMobileClient

My setup: * AWSMobileClient v2.9.8

I have tried the following solution:

  • awsconfiguration.json has information regarding "Pool A"
  • I log in a user to "Pool A" and perform business logic (success)
  • I log out the user globally and invalidate the tokens. (success)
  • I setup configuration for "Pool B" from code, I'm not sure how to specify multiple user pools in awsconfiguration.json. Not sure if it's doable.
  • I log in the user created by the backend present in "Pool B". (fails with the error message "Unable to sign in the user")

AWSMobileClient.sharedInstance().signIn( username: "user_present_in_pool_a", password: "password" ) { result, error in

        debugPrint(result, error)

        // Async sign out

        AWSMobileClient.sharedInstance().signOut(
            options: .init(
                signOutGlobally: true,
                invalidateTokens: true
            ),
            completionHandler: { error in

            debugPrint(error)

            // setup configuration for "Pool B"
            let serviceConfig = AWSServiceConfiguration(
                region: .USWest2,
                credentialsProvider: nil
            )

            let poolConfig = AWSCognitoIdentityUserPoolConfiguration(
                clientId: "pool_b_client_id", clientSecret: nil, poolId: "pool_b_id"
            )

            // init pool client
            AWSCognitoIdentityUserPool.register(
                with: serviceConfig,
                userPoolConfiguration: poolConfig,
                forKey: "some_key"
            )

            AWSMobileClient.sharedInstance().signIn(
                username: "user_present_in_pool_b",
                password: "password"
            ) { result, error in
                debugPrint(result, error)
            }
        })
    }

AWSMobileClient.Error("Could not get the end user to sign in")

noonechai
  • 11
  • 2

0 Answers0