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

后端 未结 4 1501
终归单人心
终归单人心 2020-12-16 13:05

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 c

4条回答
  •  独厮守ぢ
    2020-12-16 13:12

         // class var
         protected final AWSCognitoIdentityProviderClient identityUserPoolProviderClient;
    
        // initialize the Cognito Provider client.  This is used to talk to the user pool
        identityUserPoolProviderClient = new AWSCognitoIdentityProviderClient(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)); 
        identityUserPoolProviderClient.setRegion(RegionUtils.getRegion(USER_POOL_REGION)); 
    
    
        // ...some init code omitted        
    
    // build the request
    AdminGetUserRequest idRequest = new AdminGetUserRequest();
    idRequest.withUserPoolId(USER_POOL_ID);
    idRequest.withUsername(username);
    
    // call cognito for the result
    AdminGetUserResult result = identityUserPoolProviderClient.adminGetUser(idRequest);
    // loop through results 
    
    List userTypeList = result.getUsers();
    // loop through them
    for (UserType userType : userTypeList) {
        List attributeList = userType.getAttributes();
        for (AttributeType attribute : attributeList) {
            String attName = attribute.getName();
            String attValue = attribute.getValue();
            System.out.println(attName + ": " + attValue);
        }
    }
    

提交回复
热议问题