Search code examples
amazon-cognitoamazon-cognito-facebook

How to add user to User Pools of Amazon Congnito with Amazon PHP SDK


I can get identity id with Facebook token from Amazon Cognito by using Aws\CognitoIdentity\CognitoIdentityClient of Amazon PHP SDK ( https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.CognitoIdentity.CognitoIdentityClient.html ).

$identityClient = AWS::createClient('CognitoIdentity');
$idResp = $identityClient->getId(array(
    'AccountId' => 'MY_ACCOUNT_ID',
    'IdentityPoolId' => 'MY_IDENTITY_POOL_ID',
    'Logins' => array(
        'graph.facebook.com' => $fbUser->token,
    )
));

$identityId = $idResp["IdentityId"];

I can see the identity id in the identity browser page of Federated Identities, but there are no any user record in the Users page of User Pools.

Is this a expected result ? If it is, how can I add user info into User Pools and get them ?

Any help is appreciated.


Solution

  • If you only logged in with Facebook, a user will not show up in your user pool. Cognito user pools and cognito federated identities are unique services. Think of user pools as it's own provider - it's parallel to facebook from the point of view of your identity pool. If you want to get a user to show up in your user pool, you need to log in with user pools and pass the token to your identity pool (like you did with facebook). See our developer guide for the exact configuration you need.