I'm currently learning authentication mechanisms used in ASP.NET Core 2.0. Now, I'm trying to find what method is used for generating email confirmation token, however I cannot find the information neither in documentation nor by browsing the source code.
So far, I found out that DataProtectorTokenProvider is the class responsible for generating the token. This is the exact method which is used to create the token:
public virtual async Task<string> GenerateAsync(string purpose, UserManager<TUser> manager, TUser user)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
var ms = new MemoryStream();
var userId = await manager.GetUserIdAsync(user);
using (var writer = ms.CreateWriter())
{
// ... Here the token generation is performed
}
var protectedBytes = Protector.Protect(ms.ToArray());
return Convert.ToBase64String(protectedBytes);
}
The part which I cannot get is what is the default IDataProtectionProvider
implementation, which is used in Protector.Protect(ms.ToArray())
, and where it is registered. So my questions are:
- What is the default class used for protecting email confirmation token?
- Where is it registered?
- Can it be substituted with custom implementation when needed? If yes, how can this be achieved?
Thanks!