![.NET on AWS Banner](./../logo.png ".NET on AWS") # Authentication using the ASP.NET Core Identity Provider for Amazon Cognito ## Attributes to claims mapping In this library, the CognitoUser attributes are mapped to the [Claims](https://docs.microsoft.com/en-us/dotnet/api/system.security.claims.claim?view=netcore-2.2) of the currently logged in user [after each log in.](https://github.com/aws/aws-aspnet-cognito-identity-provider/blob/master/src/Amazon.AspNetCore.Identity.Cognito/CognitoUserClaimsPrincipalFactory.cs#L60) ## The CognitoAttribute class The ASP.NET Core Identity Provider provides a [CognitoAttribute](https://github.com/aws/aws-aspnet-cognito-identity-provider/blob/master/src/Amazon.AspNetCore.Identity.Cognito/CognitoAttribute.cs#L18) class designed to support Amazon Cognito standard attributes usecases. ## Creating new claims The ASP.NET Core Identity Provider maps all the attributes of the user pool, including custom attributes. It does not support creating new custom attributes as this is a sensitive operation. **Custom attributes cannot be removed or changed once they are added to the user pool.** For this reason, we suggest you manually create each attribute needed or carefully assess the need to programatically create them. ## Add claims for a CognitoUser The CognitoUserManager class exposes the following methods to add one or several claims to a CognitoUser user password: ```csharp /// /// Adds the specified to the . /// /// The user to add the claim to. /// The claim to add. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task AddClaimAsync(TUser user, Claim claim); /// /// Adds the specified to the . /// /// The user to add the claim to. /// The claims to add. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task AddClaimsAsync(TUser user, IEnumerable claims); ``` **Note: The claim type needs to be prefixed with 'custom:' if you are updating a custom attribute** ## Retrieve claims for a CognitoUser The CognitoUserManager class exposes the following methods to retrieve the claims of a CognitoUser user password: ```csharp /// /// Gets a list of s to be belonging to the specified as an asynchronous operation. /// /// The user whose claims to retrieve. /// /// A that represents the result of the asynchronous query, a list of s. /// Task> GetClaimsAsync(TUser user); ``` ## Update claims for a CognitoUser The CognitoUserManager class exposes the following methods to update the claims of a CognitoUser user password: ```csharp /// /// Replaces the given on the specified with the /// /// The user to replace the claim on. /// The claim to replace. /// The new claim to replace the existing with. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task ReplaceClaimAsync(TUser user, Claim claim, Claim newClaim); ``` **Note: The claim type needs to be prefixed with 'custom:' if you are updating a custom attribute** ## Remove a claims or a set of claims for a CognitoUser The CognitoUserManager class exposes the following methods to remove the claims of a CognitoUser user password: ```csharp /// /// Removes the specified from the given . /// /// The user to remove the specified from. /// The to remove. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task RemoveClaimAsync(TUser user, Claim claim); /// /// Removes the specified from the given . /// /// The user to remove the specified from. /// A collection of s to remove. /// /// The that represents the asynchronous operation, containing the /// of the operation. /// Task RemoveClaimsAsync(TUser user, IEnumerable claims); ``` **Note: The claim type needs to be prefixed with 'custom:' if you are removing a custom attribute**