Switch to protected constants for token purposes
This commit is contained in:
parent
4abf4b960c
commit
a55248c549
|
|
@ -5,12 +5,10 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Hosting;
|
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.Framework.DependencyInjection;
|
using Microsoft.Framework.DependencyInjection;
|
||||||
using Microsoft.Framework.Logging;
|
using Microsoft.Framework.Logging;
|
||||||
|
|
@ -24,6 +22,9 @@ namespace Microsoft.AspNet.Identity
|
||||||
/// <typeparam name="TUser">The type encapsulating a user.</typeparam>
|
/// <typeparam name="TUser">The type encapsulating a user.</typeparam>
|
||||||
public class UserManager<TUser> : IDisposable where TUser : class
|
public class UserManager<TUser> : IDisposable where TUser : class
|
||||||
{
|
{
|
||||||
|
protected const string ResetPasswordTokenPurpose = "ResetPassword";
|
||||||
|
protected const string ConfirmEmailTokenPurpose = "EmailConfirmation";
|
||||||
|
|
||||||
private readonly Dictionary<string, IUserTokenProvider<TUser>> _tokenProviders =
|
private readonly Dictionary<string, IUserTokenProvider<TUser>> _tokenProviders =
|
||||||
new Dictionary<string, IUserTokenProvider<TUser>>();
|
new Dictionary<string, IUserTokenProvider<TUser>>();
|
||||||
|
|
||||||
|
|
@ -204,6 +205,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
/// true if the backing user store supports user emails, otherwise false.
|
/// true if the backing user store supports user emails, otherwise false.
|
||||||
/// </value>
|
/// </value>
|
||||||
public virtual bool SupportsUserEmail
|
public virtual bool SupportsUserEmail
|
||||||
|
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
@ -720,7 +722,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual Task<string> GeneratePasswordResetTokenAsync(TUser user)
|
public virtual Task<string> GeneratePasswordResetTokenAsync(TUser user)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
return GenerateUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, "ResetPassword");
|
return GenerateUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, ResetPasswordTokenPurpose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -743,7 +745,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the token is valid and the stamp matches
|
// Make sure the token is valid and the stamp matches
|
||||||
if (!await VerifyUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, "ResetPassword", token))
|
if (!await VerifyUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, ResetPasswordTokenPurpose, token))
|
||||||
{
|
{
|
||||||
return IdentityResult.Failed(ErrorDescriber.InvalidToken());
|
return IdentityResult.Failed(ErrorDescriber.InvalidToken());
|
||||||
}
|
}
|
||||||
|
|
@ -1265,7 +1267,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual Task<string> GenerateEmailConfirmationTokenAsync(TUser user)
|
public virtual Task<string> GenerateEmailConfirmationTokenAsync(TUser user)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
return GenerateUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, "EmailConfirmation");
|
return GenerateUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, ConfirmEmailTokenPurpose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1286,7 +1288,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
throw new ArgumentNullException("user");
|
throw new ArgumentNullException("user");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await VerifyUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, "EmailConfirmation", token))
|
if (!await VerifyUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, ConfirmEmailTokenPurpose, token))
|
||||||
{
|
{
|
||||||
return IdentityResult.Failed(ErrorDescriber.InvalidToken());
|
return IdentityResult.Failed(ErrorDescriber.InvalidToken());
|
||||||
}
|
}
|
||||||
|
|
@ -1324,7 +1326,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
public virtual Task<string> GenerateChangeEmailTokenAsync(TUser user, string newEmail)
|
public virtual Task<string> GenerateChangeEmailTokenAsync(TUser user, string newEmail)
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
return GenerateUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailPurpose(newEmail));
|
return GenerateUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailTokenPurpose(newEmail));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1346,7 +1348,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the token is valid and the stamp matches
|
// Make sure the token is valid and the stamp matches
|
||||||
if (!await VerifyUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailPurpose(newEmail), token))
|
if (!await VerifyUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailTokenPurpose(newEmail), token))
|
||||||
{
|
{
|
||||||
return IdentityResult.Failed(ErrorDescriber.InvalidToken());
|
return IdentityResult.Failed(ErrorDescriber.InvalidToken());
|
||||||
}
|
}
|
||||||
|
|
@ -2042,7 +2044,12 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static string GetChangeEmailPurpose(string newEmail)
|
/// <summary>
|
||||||
|
/// Generates the token purpose used to change email
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newEmail"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected static string GetChangeEmailTokenPurpose(string newEmail)
|
||||||
{
|
{
|
||||||
return "ChangeEmail:" + newEmail;
|
return "ChangeEmail:" + newEmail;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue