Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataProtectionProvider in the Identity sample project

The official Identity 2 sample project has the code below in UserManager.Create()

public static UserManager Create(IdentityFactoryOptions<UserManager> options, IOwinContext context) {

  //...etc...

  // --- what does this block do? ---
  var dataProtectionProvider = options.DataProtectionProvider;
  if (dataProtectionProvider != null) {
    manager.UserTokenProvider = new DataProtectorTokenProvider<User>(dataProtectionProvider.Create("ASP.NET Identity"));
  }
  // --------------------------------

  //...etc...

}

The alpha/beta/RTM Identity documentation is bad or non-existent.

What does this do?

like image 942
h bob Avatar asked Sep 05 '14 11:09

h bob


1 Answers

The protection provider in the following line is used as a token provider/generator.

manager.UserTokenProvider = new DataProtectorTokenProvider<User>(dataProtectionProvider.Create("ASP.NET Identity"));

It is responsible for generating an email confirmation token or a password reset token. If you do not set this line you won't be able to use this features (an appropriate exception will be thrown). An example can be found here.

Its main purpose is to provide an implementation of the IDataProtector interface (through the Create method) which encrypts and decrypts data. An implementation for this interface in the framework is the DpapiDataProtectionProvider which should be used when the application is not hosted by ASP.NET. There are several other implementations on the web (for example one which uses the machine key for security purposes). class For more information about the DataProtectorTokenProvider have a look at the MSDN documentation.

UPDATE

Extensive Data Protection documentation is now available.

like image 73
Horizon_Net Avatar answered Oct 30 '22 15:10

Horizon_Net