/// <summary> /// Queries Cognito and returns the users in the pool. Optional filters can be applied on the users to retrieve based on their attributes. /// Providing an empty attributeFilterName parameter returns all the users in the pool. /// </summary> /// <param name="attributeFilterName"> The attribute name to filter your search on. You can only search for the following standard attributes: /// username (case-sensitive) /// email /// phone_number /// name /// given_name /// family_name /// preferred_username /// cognito:user_status (called Status in the Console) (case-insensitive) /// status (called Enabled in the Console) (case-sensitive) /// sub /// Custom attributes are not searchable. /// For more information, see Searching for Users Using the ListUsers API and Examples /// of Using the ListUsers API in the Amazon Cognito Developer Guide.</param> /// <param name="attributeFilterType"> The type of filter to apply: /// For an exact match, use = /// For a prefix ("starts with") match, use ^= /// </param> /// <param name="attributeFilterValue"> The filter value for the specified attribute.</param> /// <returns> /// The <see cref="Task"/> that represents the asynchronous operation, containing a IEnumerable of CognitoUser. /// </returns> public virtual async Task <IEnumerable <CognitoUser> > GetUsersAsync(CognitoAttribute attributeFilterName, CognitoAttributeFilterType attributeFilterType, string attributeFilterValue, CancellationToken cancellationToken) { var filter = ""; if (!string.IsNullOrWhiteSpace(attributeFilterName?.AttributeName)) { filter = (attributeFilterName.ToString() + attributeFilterType.ToString() + "\"" + attributeFilterValue + "\"").Trim(); } var request = new ListUsersRequest { UserPoolId = _pool.PoolID, Filter = filter }; ListUsersResponse response = null; var result = new List <CognitoUser>(); do { request.PaginationToken = response?.PaginationToken; try { response = await _cognitoClient.ListUsersAsync(request, cancellationToken).ConfigureAwait(false); } catch (AmazonCognitoIdentityProviderException e) { throw new CognitoServiceException("Failed to retrieve the list of users from Cognito.", e); } foreach (var user in response.Users) { result.Add(new CognitoUser(user.Username, _pool.ClientID, _pool, _cognitoClient, null, user.UserStatus.Value, user.Username, user.Attributes.ToDictionary(attribute => attribute.Name, attribute => attribute.Value))); } } while (!string.IsNullOrEmpty(response.PaginationToken)); return(result); }
/// <summary> /// Queries Cognito and returns the users in the pool. Optional filters can be applied on the users to retrieve based on their attributes. /// Providing an empty attributeFilterName parameter returns all the users in the pool. /// </summary> /// <param name="attributeFilterName"> The attribute name to filter your search on. You can only search for the following standard attributes: /// username (case-sensitive) /// email /// phone_number /// name /// given_name /// family_name /// preferred_username /// cognito:user_status (called Status in the Console) (case-insensitive) /// status (called Enabled in the Console) (case-sensitive) /// sub /// Custom attributes are not searchable. /// For more information, see Searching for Users Using the ListUsers API and Examples /// of Using the ListUsers API in the Amazon Cognito Developer Guide.</param> /// <param name="attributeFilterType"> The type of filter to apply: /// For an exact match, use = /// For a prefix ("starts with") match, use ^= /// </param> /// <param name="attributeFilterValue"> The filter value for the specified attribute.</param> /// <returns> /// The <see cref="Task"/> that represents the asynchronous operation, containing a IEnumerable of CognitoUser. /// </returns> public virtual Task <IEnumerable <CognitoUser> > GetUsersAsync(CognitoAttribute filterAttribute = null, CognitoAttributeFilterType filterType = null, string filterValue = "") { ThrowIfDisposed(); return(_userStore.GetUsersAsync(filterAttribute, filterType, filterValue, CancellationToken)); }