Cleanup DataProtectionTokenProvider

This commit is contained in:
Hao Kung 2015-01-12 12:34:16 -08:00
parent b59440d95f
commit 4eff17c9b2
2 changed files with 4 additions and 8 deletions

View File

@ -25,15 +25,11 @@ namespace Microsoft.AspNet.Identity
/// <param name="options">The configured <see cref="DataProtectionTokenProviderOptions"/>.</param> /// <param name="options">The configured <see cref="DataProtectionTokenProviderOptions"/>.</param>
public DataProtectorTokenProvider(IDataProtectionProvider dataProtectionProvider, IOptions<DataProtectionTokenProviderOptions> options) public DataProtectorTokenProvider(IDataProtectionProvider dataProtectionProvider, IOptions<DataProtectionTokenProviderOptions> options)
{ {
if (options == null || options.Options == null)
{
throw new ArgumentNullException(nameof(options));
}
if (dataProtectionProvider == null) if (dataProtectionProvider == null)
{ {
throw new ArgumentNullException(nameof(dataProtectionProvider)); throw new ArgumentNullException(nameof(dataProtectionProvider));
} }
Options = options.Options; Options = options?.Options ?? new DataProtectionTokenProviderOptions();
// Use the Name as the purpose which should usually be distinct from others // Use the Name as the purpose which should usually be distinct from others
Protector = dataProtectionProvider.CreateProtector(Name ?? "DataProtectorTokenProvider"); Protector = dataProtectionProvider.CreateProtector(Name ?? "DataProtectorTokenProvider");
} }
@ -44,7 +40,7 @@ namespace Microsoft.AspNet.Identity
/// <value> /// <value>
/// The <see cref="DataProtectionTokenProviderOptions"/> for this instance. /// The <see cref="DataProtectionTokenProviderOptions"/> for this instance.
/// </value> /// </value>
public DataProtectionTokenProviderOptions Options { get; private set; } protected DataProtectionTokenProviderOptions Options { get; private set; }
/// <summary> /// <summary>
/// Gets the <see cref="IDataProtector"/> for this instance. /// Gets the <see cref="IDataProtector"/> for this instance.
@ -52,7 +48,7 @@ namespace Microsoft.AspNet.Identity
/// <value> /// <value>
/// The <see cref="IDataProtector"/> for this instance. /// The <see cref="IDataProtector"/> for this instance.
/// </value> /// </value>
public IDataProtector Protector { get; private set; } protected IDataProtector Protector { get; private set; }
/// <summary> /// <summary>
/// Gets the name of this instance. /// Gets the name of this instance.

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity
/// <value> /// <value>
/// The name of the <see cref="DataProtectorTokenProvider{TUser}"/>. /// The name of the <see cref="DataProtectorTokenProvider{TUser}"/>.
/// </value> /// </value>
public string Name { get; set; } = "DataProtection"; public string Name { get; set; } = "DataProtectorTokenProvider";
/// <summary> /// <summary>
/// Gets or sets the amount of time a generated token remains valid. /// Gets or sets the amount of time a generated token remains valid.