I want to implement email confirmation with digit code for my .net core web app. I make use of the GenerateEmailConfirmationTokenAsync from the UserManager class, but it returns a token instead of a digit code. I think I should create a custom implementation using the IUserTokenProvider interface, but I cant find any example.
How can I implement this using the IUserTokenProvider?
There is an existing implementation in ASP.NET Core Identity that does that.
The TotpSecurityStampBasedTokenProvider class (implementation of IUserTwoFactorTokenProvider interface) generates 6-digit tokens that expire.
TotpSecurityStampBasedTokenProvider
is further inherited by EmailTokenProvider, but GenerateAsync method is reused from TotpSecurityStampBasedTokenProvider
(not overridden).
These classes use user's security stamp to generate tokens, and provide their own modifiers, but the actual token generation is done by GenerateCode method from Rfc6238AuthenticationService class.
So, you can use the existing implementations:
TotpSecurityStampBasedTokenProvider
EmailTokenProvider
(it does the same as the above one)Rfc6238AuthenticationService
if you really want to customize the token