Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I look up a cognito user by their sub/UUID?

I want to look up a user in my Cognito user pool by their sub, which as far as I can tell, is just their UUID. I would like to do this in Java within a Lambda function but cannot find how to do this in AWS's documenation. Any thoughts?

like image 295
Mark Keane Avatar asked Apr 19 '17 06:04

Mark Keane


2 Answers

Now it works. http://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html

"sub" in list of supported attributes. Example for JavaScript:

var cog = new AWS.CognitoIdentityServiceProvider();

var filter = "sub = \"" + userSub + "\"";
var req = {
    "Filter": filter,
    "UserPoolId": "your pool id" // looks like us-east-9_KDFn1cvys
};

cog.listUsers(req, function(err, data) {
    if (err) {
        console.log(err);
    }
    else {
        if (data.Users.length === 1){ //as far as we search by sub, should be only one user.
            var user = data.Users[0];
            var attributes = data.Users[0].Attributes;
        } else {
            console.log("Something wrong.");
        }
    }
});
like image 62
Vadim Leb Avatar answered Sep 26 '22 07:09

Vadim Leb


As of today this is not possible with Cognito User Pools.

Users can only be looked up using their username or aliases. ListUsers API also allows users to be searched by providing search filters on some standard attributes but sub is not one of them.

like image 22
Chetan Mehta Avatar answered Sep 26 '22 07:09

Chetan Mehta