Asp.Net Identity default expiration time is 1 day. Some time its require to change based on our requirement.
Default property initialization on DataProtectionTokenProviderOptions class is
Require customization for change to default token expiration time.
Following step require to change default expiration token time.
Step 1 : Create new class with name DefaultDataProtectorTokenProviderOptions and Inherit from DataProtectionTokenProviderOptions class.
Step 2 : Create new class with name DefaultDataProtectorTokenProvider and Inherit from DataProtectorTokenProvider class.
Step 4: Declare private variable for provider name
Step 5 : Under ConfigureServices method add following code for token expiration time change.
Here you can see set time span for token expiration.
You can get the source code from GitHub.
Hope you like this so please keep reading.
Default property initialization on DataProtectionTokenProviderOptions class is
public TimeSpan TokenLifespan { get; set; } = TimeSpan.FromDays(1);
Require customization for change to default token expiration time.
Following step require to change default expiration token time.
Step 1 : Create new class with name DefaultDataProtectorTokenProviderOptions and Inherit from DataProtectionTokenProviderOptions class.
public class DefaultDataProtectorTokenProviderOptions : DataProtectionTokenProviderOptions { }
Step 2 : Create new class with name DefaultDataProtectorTokenProvider and Inherit from DataProtectorTokenProvider class.
public class DefaultDataProtectorTokenProviderStep 3 : Time to use above classes on Startup class and AddTokenProvider.: DataProtectorTokenProvider where TUser : class { public DefaultDataProtectorTokenProvider(IDataProtectionProvider dataProtectionProvider, IOptions options) : base(dataProtectionProvider, options) { } }
Step 4: Declare private variable for provider name
private const string _defaultTokenProviderName = "Default";
Step 5 : Under ConfigureServices method add following code for token expiration time change.
Here you can see set time span for token expiration.
// Set time span for token expiration time options.TokenLifespan = TimeSpan.FromMinutes(15);
You can get the source code from GitHub.
Hope you like this so please keep reading.