diff --git a/src/Microsoft.AspNet.Identity/DataProtectionTokenProvider.cs b/src/Microsoft.AspNet.Identity/DataProtectionTokenProvider.cs index ae7bdfc960..b50ad1ecaa 100644 --- a/src/Microsoft.AspNet.Identity/DataProtectionTokenProvider.cs +++ b/src/Microsoft.AspNet.Identity/DataProtectionTokenProvider.cs @@ -1,24 +1,28 @@ -using Microsoft.AspNet.Security.DataProtection; -using Microsoft.Framework.OptionsModel; +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Security.DataProtection; +using Microsoft.Framework.OptionsModel; + namespace Microsoft.AspNet.Identity { - public class DataProtectionTokenProviderOptions - { - public string Name { get; set; } = "DataProtection"; - public TimeSpan TokenLifespan { get; set; } = TimeSpan.FromDays(1); - } - /// - /// Token provider that uses an IDataProtector to generate encrypted tokens based off of the security stamp + /// Provides protection and validation of identity tokens. /// + /// The type used to represent a user. public class DataProtectorTokenProvider : IUserTokenProvider where TUser : class { + /// + /// Initializes a new instance of the class. + /// + /// The system data protection provider. + /// The configured . public DataProtectorTokenProvider(IDataProtectionProvider dataProtectionProvider, IOptions options) { if (options == null || options.Options == null) @@ -34,18 +38,38 @@ namespace Microsoft.AspNet.Identity Protector = dataProtectionProvider.CreateProtector(Name ?? "DataProtectorTokenProvider"); } + /// + /// Gets the for this instance. + /// + /// + /// The for this instance. + /// public DataProtectionTokenProviderOptions Options { get; private set; } + + /// + /// Gets the for this instance. + /// + /// + /// The for this instance. + /// public IDataProtector Protector { get; private set; } + /// + /// Gets the name of this instance. + /// + /// + /// The name of this instance. + /// public string Name { get { return Options.Name; } } /// - /// Generate a protected string for a user + /// Generates a protected token for the specified . /// - /// - /// - /// - /// + /// The purpose the token will be used for. + /// The to retrieve user properties from. + /// The the token will be generated from. + /// A to observe while waiting for the tasks to complete. + /// A that contains the protected token. public async Task GenerateAsync(string purpose, UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)) { @@ -72,13 +96,14 @@ namespace Microsoft.AspNet.Identity } /// - /// Return false if the token is not valid + /// Validates the protected for the specified and . /// - /// - /// - /// - /// - /// + /// The purpose the token was be used for. + /// The token to validate. + /// The to retrieve user properties from. + /// The the token was generated for. + /// A to observe while waiting for the tasks to complete. + /// A that is true if the token is valid, otherwise false. public async Task ValidateAsync(string purpose, string token, UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)) { @@ -128,11 +153,13 @@ namespace Microsoft.AspNet.Identity } /// - /// Returns false because tokens are two long to be used for two factor + /// Returns a indicating whether a token generated by this instance + /// can be used as a Two Factor Authentication token. /// - /// - /// - /// + /// The to retrieve user properties from. + /// The the token was generated for. + /// True if a token generated by this instance can be used as a Two Factor Authentication token, otherwise false. + /// This method will always return false for instances of . public Task CanGenerateTwoFactorTokenAsync(UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)) { @@ -140,12 +167,13 @@ namespace Microsoft.AspNet.Identity } /// - /// This provider no-ops by default when asked to notify a user + /// Creates a notification task for A based on the supplied . /// - /// - /// - /// - /// + /// The token to generate notifications for.. + /// The to retrieve user properties from. + /// The the token was generated for. + /// A to observe while waiting for the tasks to complete. + /// A that represents the started task. public Task NotifyAsync(string token, UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)) { @@ -153,7 +181,9 @@ namespace Microsoft.AspNet.Identity } } - // Based on Levi's authentication sample + /// + /// Utility extensions to streams + /// internal static class StreamExtensions { internal static readonly Encoding DefaultEncoding = new UTF8Encoding(false, true); diff --git a/src/Microsoft.AspNet.Identity/DataProtectionTokenProviderOptions.cs b/src/Microsoft.AspNet.Identity/DataProtectionTokenProviderOptions.cs new file mode 100644 index 0000000000..e7a6ab7170 --- /dev/null +++ b/src/Microsoft.AspNet.Identity/DataProtectionTokenProviderOptions.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNet.Identity +{ + /// + /// Contains options for the . + /// + public class DataProtectionTokenProviderOptions + { + /// + /// Gets or sets the name of the . + /// + /// + /// The name of the . + /// + public string Name { get; set; } = "DataProtection"; + + /// + /// Gets or sets the amount of time a generated token remains valid. + /// + /// + /// The amount of time a generated token remains valid. + /// + public TimeSpan TokenLifespan { get; set; } = TimeSpan.FromDays(1); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/Microsoft.AspNet.Identity.kproj b/src/Microsoft.AspNet.Identity/Microsoft.AspNet.Identity.kproj index 318f83366a..2c8bf644b8 100644 --- a/src/Microsoft.AspNet.Identity/Microsoft.AspNet.Identity.kproj +++ b/src/Microsoft.AspNet.Identity/Microsoft.AspNet.Identity.kproj @@ -1,4 +1,4 @@ - + 14.0 @@ -14,4 +14,9 @@ 2.0 - + + + + + + \ No newline at end of file