![.NET on AWS Banner](./../logo.png ".NET on AWS") # Users management using the ASP.NET Core Identity Provider for Amazon Cognito ## Get all CognitoUser or a subset of CognitoUser from the pool The CognitoUserManager class exposes the following method to filter users in the pool: ```csharp /// /// 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. /// /// The attribute name to filter your search on /// The type of filter to apply (exact match or starts with) /// The filter value for the specified attribute. /// /// The that represents the asynchronous operation, containing a IEnumerable of CognitoUser. /// Task> GetUsersAsync(CognitoAttribute filterAttribute = null, CognitoAttributeFilterType filterType = null, string filterValue = ""); ``` ## Find a CognitoUser by name, email or id The CognitoUserManager class exposes the following methods to retrieve a user in the pool: ```csharp /// /// Gets the user, if any, associated with the normalized value of the specified email address. /// /// The email address to return the user for. /// /// The task object containing the results of the asynchronous lookup operation, the user, if any, associated with a normalized value of the specified email address. /// Task FindByEmailAsync(string email); /// /// Finds and returns a user, if any, who has the specified . /// /// The user ID to search for. /// /// The that represents the asynchronous operation, containing the user matching the specified if it exists. /// Task FindByIdAsync(string userId); /// /// Finds and returns a user, if any, who has the specified user name. /// /// The user name to search for. /// /// The that represents the asynchronous operation, containing the user matching the specified if it exists. /// Task FindByNameAsync(string userName); ``` ## Create a new CognitoUser You will first need to request a new CognitoUser object instance from the CognitoUserPool class using one of the following methods: ```csharp /// /// Gets a CognitoUser with the corresponding userID /// /// The userID of the corresponding user /// Returns a CognitoUser with the corresponding userID CognitoUser GetUser(string userID); /// /// Gets a CognitoUser with the corresponding userID, status and attributes /// /// The userID of the corresponding user /// The status of the corresponding user /// The attributes of the corresponding user /// Returns a CognitoUser with the corresponding userID CognitoUser GetUser(string userID, string status, Dictionary attributes); ``` The CognitoUserManager class exposes the following method to add the CognitoUser to the pool: ```csharp /// /// Creates the specified in Cognito with a generated password sent to the user, /// as an asynchronous operation. /// /// The user to create. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task CreateAsync(TUser user); ``` A full example of user creation is available in the [sample web application.](https://github.com/aws/aws-aspnet-cognito-identity-provider/blob/master/samples/Samples/Areas/Identity/Pages/Account/Register.cshtml.cs#L71) ## Confirm a CognitoUser Sign up using the confirmation token Once the CognitoUser added to the pool, a confirmation token is sent either to the CognitoUser email or phone number. The CognitoUserManager class exposes the following method to verify the CognitoUser account. It also verifies the medium used to receive the token: ```csharp /// /// Confirms the specified account with the specified /// he was sent by email or sms, /// as an asynchronous operation. /// When a new user is confirmed, the user's attribute through which the /// confirmation code was sent (email address or phone number) is marked as verified. /// If this attribute is also set to be used as an alias, then the user can sign in with /// that attribute (email address or phone number) instead of the username. /// /// The user to confirm. /// The confirmation code that was sent by email or sms. /// If set to true, this resolves potential alias conflicts by marking the attribute email or phone number verified. /// If set to false and an alias conflict exists, then the user confirmation will fail. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task ConfirmSignUpAsync(TUser user, string confirmationCode, bool forcedAliasCreation); ``` ## Confirm a CognitoUser Sign up using Admin privileges Once the CognitoUser added to the pool, a confirmation token is sent either to the CognitoUser email or phone number. You can force the confirmation of the CognitoUser account using the following method of the CognitoUserManager, regardless of the confirmation token: ```csharp /// /// Admin confirms the specified /// as an asynchronous operation. /// /// The user to confirm. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task AdminConfirmSignUpAsync(TUser user); ``` **Note: this does not confirm the medium used to receive the confirmation token (phone number or email).** ## Resend the CognitoUser sign up confirmation token The CognitoUserManager class exposes the following method to resend the CognitoUser sign up confirmation token: ```csharp /// /// Resends the account signup confirmation code for the specified /// as an asynchronous operation. /// /// The user to resend the account signup confirmation code for. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task ResendSignupConfirmationCodeAsync(TUser user); ``` ## Update a CognitoUser attributes After making changes to a CognitoUser attributes property, you can call the following method on the CognitoUserManager class: ```csharp /// /// Updates the user attributes. /// /// The user with the new attributes values changed. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task UpdateUserAsync(TUser user); ``` ## Delete a CognitoUser from the pool The CognitoUserManager class exposes the following method to delete a user from the pool: ```csharp /// /// Deletes the specified from the user pool. /// /// The user to delete. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task DeleteAsync(TUser user); ```