The Microsoft team provides a pretty good library (with minor issues which I will discuss in other posts) for managing users and authentication. AspIdentity is very configurable and it meets most demands for small and large applications.
You can use the built in method to add an Identity and this adds all the dependencies and some default services that are required for the UserManager, SignInManager and RoleManager
Defining the types of token providers
The IdentityOptions allows you to define the names of the token providers you want to use in the application, but be aware, they are not adde by default. In the snippet below I am only setting up the names for various token providers (names which are taken from the default static configuration but you can place any name as long as it will match with the added token provider)
Note: If you don’t specify the token provider for each type, the TokenOptions will assume most of them will be handled by the default provider:
The names are defined in TokenOptions class as:
Register the token providers
To actually add the token providers, you can use the built in extension method which adds default implementations of these providers:
Personally I think it’s clearer if I just add them as:
1. EmailConfirmationTokenProvider
This provider is used in the UserManager to generate and validate the email confirmation token
2. PasswordResetTokenProvider
This provider is used by the UserManager to generate and validate the password reset token
3. ChangeEmailTokenProvider
This provider is used by the UserManager to generate and validate the change email token
4. ChangePhoneNumberTokenProvider
This provider is used by the UserManager to generate and validate the change phone number token
5. AuthenticatorTokenProvider
This provider is used to validate a an authenticator key which is internally set up by Identity. As this is a more complicated topic I will have a sepparate article on it.