AddEFStores: Infer generics from DbContext
This commit is contained in:
parent
d4d105d5b5
commit
57a25d080d
|
|
@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// <typeparam name="TRoleClaim">The type of the role claim object.</typeparam>
|
||||
/// <typeparam name="TUserToken">The type of the user token object.</typeparam>
|
||||
public abstract class IdentityDbContext<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken> : DbContext
|
||||
where TUser : IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin>
|
||||
where TUser : IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>
|
||||
where TRole : IdentityRole<TKey, TUserRole, TRoleClaim>
|
||||
where TKey : IEquatable<TKey>
|
||||
where TUserClaim : IdentityUserClaim<TKey>
|
||||
|
|
@ -162,6 +162,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
b.HasMany(u => u.Claims).WithOne().HasForeignKey(uc => uc.UserId).IsRequired();
|
||||
b.HasMany(u => u.Logins).WithOne().HasForeignKey(ul => ul.UserId).IsRequired();
|
||||
b.HasMany(u => u.Roles).WithOne().HasForeignKey(ur => ur.UserId).IsRequired();
|
||||
b.HasMany(u => u.Tokens).WithOne().HasForeignKey(ut => ut.UserId).IsRequired();
|
||||
});
|
||||
|
||||
builder.Entity<TRole>(b =>
|
||||
|
|
|
|||
|
|
@ -24,60 +24,53 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
public static IdentityBuilder AddEntityFrameworkStores<TContext>(this IdentityBuilder builder)
|
||||
where TContext : DbContext
|
||||
{
|
||||
var keyType = InferKeyType(typeof(TContext));
|
||||
AddStores(builder.Services, builder.UserType, builder.RoleType, typeof(TContext), keyType);
|
||||
AddStores(builder.Services, builder.UserType, builder.RoleType, typeof(TContext));
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an Entity Framework implementation of identity information stores.
|
||||
/// </summary>
|
||||
/// <typeparam name="TContext">The Entity Framework database context to use.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key used for the users and roles.</typeparam>
|
||||
/// <param name="builder">The <see cref="IdentityBuilder"/> instance this method extends.</param>
|
||||
/// <returns>The <see cref="IdentityBuilder"/> instance this method extends.</returns>
|
||||
public static IdentityBuilder AddEntityFrameworkStores<TContext, TKey>(this IdentityBuilder builder)
|
||||
where TContext : DbContext
|
||||
where TKey : IEquatable<TKey>
|
||||
private static void AddStores(IServiceCollection services, Type userType, Type roleType, Type contextType)
|
||||
{
|
||||
AddStores(builder.Services, builder.UserType, builder.RoleType, typeof(TContext), typeof(TKey));
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static void AddStores(IServiceCollection services, Type userType, Type roleType, Type contextType, Type keyType)
|
||||
{
|
||||
var identityUserType = typeof(IdentityUser<>).MakeGenericType(keyType);
|
||||
if (!identityUserType.GetTypeInfo().IsAssignableFrom(userType.GetTypeInfo()))
|
||||
var identityUserType = FindGenericBaseType(userType, typeof(IdentityUser<,,,,>));
|
||||
if (identityUserType == null)
|
||||
{
|
||||
throw new InvalidOperationException(Resources.NotIdentityUser);
|
||||
}
|
||||
var identityRoleType = typeof(IdentityRole<>).MakeGenericType(keyType);
|
||||
if (!identityRoleType.GetTypeInfo().IsAssignableFrom(roleType.GetTypeInfo()))
|
||||
var identityRoleType = FindGenericBaseType(roleType, typeof(IdentityRole<,,>));
|
||||
if (identityRoleType == null)
|
||||
{
|
||||
throw new InvalidOperationException(Resources.NotIdentityRole);
|
||||
}
|
||||
|
||||
services.TryAddScoped(
|
||||
typeof(IUserStore<>).MakeGenericType(userType),
|
||||
typeof(UserStore<,,,>).MakeGenericType(userType, roleType, contextType, keyType));
|
||||
typeof(UserStore<,,,,,,,,>).MakeGenericType(userType, roleType, contextType,
|
||||
identityUserType.GenericTypeArguments[0],
|
||||
identityUserType.GenericTypeArguments[1],
|
||||
identityUserType.GenericTypeArguments[2],
|
||||
identityUserType.GenericTypeArguments[3],
|
||||
identityUserType.GenericTypeArguments[4],
|
||||
identityRoleType.GenericTypeArguments[2]));
|
||||
services.TryAddScoped(
|
||||
typeof(IRoleStore<>).MakeGenericType(roleType),
|
||||
typeof(RoleStore<,,>).MakeGenericType(roleType, contextType, keyType));
|
||||
typeof(RoleStore<,,,,>).MakeGenericType(roleType, contextType,
|
||||
identityRoleType.GenericTypeArguments[0],
|
||||
identityRoleType.GenericTypeArguments[1],
|
||||
identityRoleType.GenericTypeArguments[2]));
|
||||
}
|
||||
|
||||
private static Type InferKeyType(Type contextType)
|
||||
private static TypeInfo FindGenericBaseType(Type currentType, Type genericBaseType)
|
||||
{
|
||||
var type = contextType.GetTypeInfo();
|
||||
var type = currentType.GetTypeInfo();
|
||||
while (type.BaseType != null)
|
||||
{
|
||||
type = type.BaseType.GetTypeInfo();
|
||||
var genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
|
||||
if (genericType != null && genericType == typeof(IdentityDbContext<,,>))
|
||||
if (genericType != null && genericType == genericBaseType)
|
||||
{
|
||||
return type.GenericTypeArguments[2];
|
||||
return type;
|
||||
}
|
||||
}
|
||||
// Default is string
|
||||
return typeof(string);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// Represents a user in the identity system
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">The type used for the primary key for the user.</typeparam>
|
||||
public class IdentityUser<TKey> : IdentityUser<TKey, IdentityUserClaim<TKey>, IdentityUserRole<TKey>, IdentityUserLogin<TKey>>
|
||||
public class IdentityUser<TKey> : IdentityUser<TKey, IdentityUserClaim<TKey>, IdentityUserRole<TKey>, IdentityUserLogin<TKey>, IdentityUserToken<TKey>>
|
||||
where TKey : IEquatable<TKey>
|
||||
{ }
|
||||
|
||||
|
|
@ -50,7 +50,8 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// <typeparam name="TUserClaim">The type representing a claim.</typeparam>
|
||||
/// <typeparam name="TUserRole">The type representing a user role.</typeparam>
|
||||
/// <typeparam name="TUserLogin">The type representing a user external login.</typeparam>
|
||||
public class IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin> where TKey : IEquatable<TKey>
|
||||
/// <typeparam name="TUserToken">The type representing a user external login.</typeparam>
|
||||
public class IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken> where TKey : IEquatable<TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="IdentityUser{TKey}"/>.
|
||||
|
|
@ -163,6 +164,11 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// </summary>
|
||||
public virtual ICollection<TUserLogin> Logins { get; } = new List<TUserLogin>();
|
||||
|
||||
/// <summary>
|
||||
/// Navigation property for this users tokens.
|
||||
/// </summary>
|
||||
public virtual ICollection<TUserToken> Tokens { get; } = new List<TUserToken>();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the username for this user.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
= new ResourceManager("Microsoft.AspNetCore.Identity.EntityFrameworkCore.Resources", typeof(Resources).GetTypeInfo().Assembly);
|
||||
|
||||
/// <summary>
|
||||
/// AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey>. If you are specifying more generic arguments, use AddRoleStore<TStore>() where TStore is your custom IRoleStore that uses your generics instead.
|
||||
/// AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.
|
||||
/// </summary>
|
||||
internal static string NotIdentityRole
|
||||
{
|
||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey>. If you are specifying more generic arguments, use AddRoleStore<TStore>() where TStore is your custom IRoleStore that uses your generics instead.
|
||||
/// AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.
|
||||
/// </summary>
|
||||
internal static string FormatNotIdentityRole()
|
||||
{
|
||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey>. If you are specifying more generic arguments, use IdentityBuilder.AddUserStore<TStore>() where TStore is your custom IUserStore that uses your generics instead.
|
||||
/// AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.
|
||||
/// </summary>
|
||||
internal static string NotIdentityUser
|
||||
{
|
||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey>. If you are specifying more generic arguments, use IdentityBuilder.AddUserStore<TStore>() where TStore is your custom IUserStore that uses your generics instead.
|
||||
/// AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.
|
||||
/// </summary>
|
||||
internal static string FormatNotIdentityUser()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -118,11 +118,11 @@
|
|||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="NotIdentityRole" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey>. If you are specifying more generic arguments, use AddRoleStore<TStore>() where TStore is your custom IRoleStore that uses your generics instead.</value>
|
||||
<value>AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.</value>
|
||||
<comment>error when the role does not derive from IdentityRole</comment>
|
||||
</data>
|
||||
<data name="NotIdentityUser" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey>. If you are specifying more generic arguments, use IdentityBuilder.AddUserStore<TStore>() where TStore is your custom IUserStore that uses your generics instead.</value>
|
||||
<value>AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.</value>
|
||||
<comment>error when the user does not derive from IdentityUser</comment>
|
||||
</data>
|
||||
<data name="RoleNotFound" xml:space="preserve">
|
||||
|
|
|
|||
|
|
@ -64,17 +64,6 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// <param name="context">The <see cref="DbContext"/>.</param>
|
||||
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
|
||||
public RoleStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a entity representing a role claim.
|
||||
/// </summary>
|
||||
/// <param name="role">The associated role.</param>
|
||||
/// <param name="claim">The associated claim.</param>
|
||||
/// <returns>The role claim entity.</returns>
|
||||
protected override IdentityRoleClaim<TKey> CreateRoleClaim(TRole role, Claim claim)
|
||||
{
|
||||
return new IdentityRoleClaim<TKey> { RoleId = role.Id, ClaimType = claim.Type, ClaimValue = claim.Value };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -85,14 +74,14 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// <typeparam name="TKey">The type of the primary key for a role.</typeparam>
|
||||
/// <typeparam name="TUserRole">The type of the class representing a user role.</typeparam>
|
||||
/// <typeparam name="TRoleClaim">The type of the class representing a role claim.</typeparam>
|
||||
public abstract class RoleStore<TRole, TContext, TKey, TUserRole, TRoleClaim> :
|
||||
public class RoleStore<TRole, TContext, TKey, TUserRole, TRoleClaim> :
|
||||
IQueryableRoleStore<TRole>,
|
||||
IRoleClaimStore<TRole>
|
||||
where TRole : IdentityRole<TKey, TUserRole, TRoleClaim>
|
||||
where TKey : IEquatable<TKey>
|
||||
where TContext : DbContext
|
||||
where TUserRole : IdentityUserRole<TKey>
|
||||
where TRoleClaim : IdentityRoleClaim<TKey>
|
||||
where TUserRole : IdentityUserRole<TKey>, new()
|
||||
where TRoleClaim : IdentityRoleClaim<TKey>, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a new instance of <see cref="RoleStore{TRole, TContext, TKey, TUserRole, TRoleClaim}"/>.
|
||||
|
|
@ -458,6 +447,9 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// <param name="role">The associated role.</param>
|
||||
/// <param name="claim">The associated claim.</param>
|
||||
/// <returns>The role claim entity.</returns>
|
||||
protected abstract TRoleClaim CreateRoleClaim(TRole role, Claim claim);
|
||||
protected virtual TRoleClaim CreateRoleClaim(TRole role, Claim claim)
|
||||
{
|
||||
return new TRoleClaim { RoleId = role.Id, ClaimType = claim.Type, ClaimValue = claim.Value };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// <typeparam name="TRole">The type representing a role.</typeparam>
|
||||
/// <typeparam name="TContext">The type of the data context class used to access the store.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a role.</typeparam>
|
||||
public class UserStore<TUser, TRole, TContext, TKey> : UserStore<TUser, TRole, TContext, TKey, IdentityUserClaim<TKey>, IdentityUserRole<TKey>, IdentityUserLogin<TKey>, IdentityUserToken<TKey>>
|
||||
public class UserStore<TUser, TRole, TContext, TKey> : UserStore<TUser, TRole, TContext, TKey, IdentityUserClaim<TKey>, IdentityUserRole<TKey>, IdentityUserLogin<TKey>, IdentityUserToken<TKey>, IdentityRoleClaim<TKey>>
|
||||
where TUser : IdentityUser<TKey>
|
||||
where TRole : IdentityRole<TKey>
|
||||
where TContext : DbContext
|
||||
|
|
@ -81,103 +81,8 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// <param name="context">The <see cref="DbContext"/>.</param>
|
||||
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
|
||||
public UserStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
|
||||
|
||||
/// <summary>
|
||||
/// Called to create a new instance of a <see cref="IdentityUserRole{TKey}"/>.
|
||||
/// </summary>
|
||||
/// <param name="user">The associated user.</param>
|
||||
/// <param name="role">The associated role.</param>
|
||||
/// <returns></returns>
|
||||
protected override IdentityUserRole<TKey> CreateUserRole(TUser user, TRole role)
|
||||
{
|
||||
return new IdentityUserRole<TKey>()
|
||||
{
|
||||
UserId = user.Id,
|
||||
RoleId = role.Id
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to create a new instance of a <see cref="IdentityUserClaim{TKey}"/>.
|
||||
/// </summary>
|
||||
/// <param name="user">The associated user.</param>
|
||||
/// <param name="claim">The associated claim.</param>
|
||||
/// <returns></returns>
|
||||
protected override IdentityUserClaim<TKey> CreateUserClaim(TUser user, Claim claim)
|
||||
{
|
||||
var userClaim = new IdentityUserClaim<TKey> { UserId = user.Id };
|
||||
userClaim.InitializeFromClaim(claim);
|
||||
return userClaim;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to create a new instance of a <see cref="IdentityUserLogin{TKey}"/>.
|
||||
/// </summary>
|
||||
/// <param name="user">The associated user.</param>
|
||||
/// <param name="login">The sasociated login.</param>
|
||||
/// <returns></returns>
|
||||
protected override IdentityUserLogin<TKey> CreateUserLogin(TUser user, UserLoginInfo login)
|
||||
{
|
||||
return new IdentityUserLogin<TKey>
|
||||
{
|
||||
UserId = user.Id,
|
||||
ProviderKey = login.ProviderKey,
|
||||
LoginProvider = login.LoginProvider,
|
||||
ProviderDisplayName = login.ProviderDisplayName
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to create a new instance of a <see cref="IdentityUserToken{TKey}"/>.
|
||||
/// </summary>
|
||||
/// <param name="user">The associated user.</param>
|
||||
/// <param name="loginProvider">The associated login provider.</param>
|
||||
/// <param name="name">The name of the user token.</param>
|
||||
/// <param name="value">The value of the user token.</param>
|
||||
/// <returns></returns>
|
||||
protected override IdentityUserToken<TKey> CreateUserToken(TUser user, string loginProvider, string name, string value)
|
||||
{
|
||||
return new IdentityUserToken<TKey>
|
||||
{
|
||||
UserId = user.Id,
|
||||
LoginProvider = loginProvider,
|
||||
Name = name,
|
||||
Value = value
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a new instance of a persistence store for the specified user and role types.
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser">The type representing a user.</typeparam>
|
||||
/// <typeparam name="TRole">The type representing a role.</typeparam>
|
||||
/// <typeparam name="TContext">The type of the data context class used to access the store.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a role.</typeparam>
|
||||
/// <typeparam name="TUserClaim">The type representing a claim.</typeparam>
|
||||
/// <typeparam name="TUserRole">The type representing a user role.</typeparam>
|
||||
/// <typeparam name="TUserLogin">The type representing a user external login.</typeparam>
|
||||
/// <typeparam name="TUserToken">The type representing a user token.</typeparam>
|
||||
public abstract class UserStore<TUser, TRole, TContext, TKey, TUserClaim, TUserRole, TUserLogin, TUserToken> :
|
||||
UserStore<TUser, TRole, TContext, TKey,TUserClaim, TUserRole, TUserLogin, TUserToken, IdentityRoleClaim<TKey>>
|
||||
where TUser : IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin>
|
||||
where TRole : IdentityRole<TKey, TUserRole, IdentityRoleClaim<TKey>>
|
||||
where TContext : DbContext
|
||||
where TKey : IEquatable<TKey>
|
||||
where TUserClaim : IdentityUserClaim<TKey>
|
||||
where TUserRole : IdentityUserRole<TKey>
|
||||
where TUserLogin : IdentityUserLogin<TKey>
|
||||
where TUserToken : IdentityUserToken<TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="UserStore"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">The context used to access the store.</param>
|
||||
/// <param name="describer">The <see cref="IdentityErrorDescriber"/> used to describe store errors.</param>
|
||||
public UserStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Represents a new instance of a persistence store for the specified user and role types.
|
||||
/// </summary>
|
||||
|
|
@ -190,7 +95,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
/// <typeparam name="TUserLogin">The type representing a user external login.</typeparam>
|
||||
/// <typeparam name="TUserToken">The type representing a user token.</typeparam>
|
||||
/// <typeparam name="TRoleClaim">The type representing a role claim.</typeparam>
|
||||
public abstract class UserStore<TUser, TRole, TContext, TKey, TUserClaim, TUserRole, TUserLogin, TUserToken, TRoleClaim> :
|
||||
public class UserStore<TUser, TRole, TContext, TKey, TUserClaim, TUserRole, TUserLogin, TUserToken, TRoleClaim> :
|
||||
IUserLoginStore<TUser>,
|
||||
IUserRoleStore<TUser>,
|
||||
IUserClaimStore<TUser>,
|
||||
|
|
@ -204,15 +109,15 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
IUserAuthenticationTokenStore<TUser>,
|
||||
IUserAuthenticatorKeyStore<TUser>,
|
||||
IUserTwoFactorRecoveryCodeStore<TUser>
|
||||
where TUser : IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin>
|
||||
where TUser : IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>
|
||||
where TRole : IdentityRole<TKey, TUserRole, TRoleClaim>
|
||||
where TContext : DbContext
|
||||
where TKey : IEquatable<TKey>
|
||||
where TUserClaim : IdentityUserClaim<TKey>
|
||||
where TUserRole : IdentityUserRole<TKey>
|
||||
where TUserLogin : IdentityUserLogin<TKey>
|
||||
where TUserToken : IdentityUserToken<TKey>
|
||||
where TRoleClaim : IdentityRoleClaim<TKey>
|
||||
where TUserClaim : IdentityUserClaim<TKey>, new()
|
||||
where TUserRole : IdentityUserRole<TKey>, new()
|
||||
where TUserLogin : IdentityUserLogin<TKey>, new()
|
||||
where TUserToken : IdentityUserToken<TKey>, new()
|
||||
where TRoleClaim : IdentityRoleClaim<TKey>, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="UserStore"/>.
|
||||
|
|
@ -249,38 +154,68 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore
|
|||
private DbSet<TUserToken> UserTokens { get { return Context.Set<TUserToken>(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new entity to represent a user role.
|
||||
/// Called to create a new instance of a <see cref="IdentityUserRole{TKey}"/>.
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="role"></param>
|
||||
/// <param name="user">The associated user.</param>
|
||||
/// <param name="role">The associated role.</param>
|
||||
/// <returns></returns>
|
||||
protected abstract TUserRole CreateUserRole(TUser user, TRole role);
|
||||
protected virtual TUserRole CreateUserRole(TUser user, TRole role)
|
||||
{
|
||||
return new TUserRole()
|
||||
{
|
||||
UserId = user.Id,
|
||||
RoleId = role.Id
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new entity representing a user claim.
|
||||
/// Called to create a new instance of a <see cref="IdentityUserClaim{TKey}"/>.
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="claim"></param>
|
||||
/// <param name="user">The associated user.</param>
|
||||
/// <param name="claim">The associated claim.</param>
|
||||
/// <returns></returns>
|
||||
protected abstract TUserClaim CreateUserClaim(TUser user, Claim claim);
|
||||
protected virtual TUserClaim CreateUserClaim(TUser user, Claim claim)
|
||||
{
|
||||
var userClaim = new TUserClaim { UserId = user.Id };
|
||||
userClaim.InitializeFromClaim(claim);
|
||||
return userClaim;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new entity representing a user login.
|
||||
/// Called to create a new instance of a <see cref="IdentityUserLogin{TKey}"/>.
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="login"></param>
|
||||
/// <param name="user">The associated user.</param>
|
||||
/// <param name="login">The sasociated login.</param>
|
||||
/// <returns></returns>
|
||||
protected abstract TUserLogin CreateUserLogin(TUser user, UserLoginInfo login);
|
||||
protected virtual TUserLogin CreateUserLogin(TUser user, UserLoginInfo login)
|
||||
{
|
||||
return new TUserLogin
|
||||
{
|
||||
UserId = user.Id,
|
||||
ProviderKey = login.ProviderKey,
|
||||
LoginProvider = login.LoginProvider,
|
||||
ProviderDisplayName = login.ProviderDisplayName
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new entity representing a user token.
|
||||
/// Called to create a new instance of a <see cref="IdentityUserToken{TKey}"/>.
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="loginProvider"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="user">The associated user.</param>
|
||||
/// <param name="loginProvider">The associated login provider.</param>
|
||||
/// <param name="name">The name of the user token.</param>
|
||||
/// <param name="value">The value of the user token.</param>
|
||||
/// <returns></returns>
|
||||
protected abstract TUserToken CreateUserToken(TUser user, string loginProvider, string name, string value);
|
||||
protected virtual TUserToken CreateUserToken(TUser user, string loginProvider, string name, string value)
|
||||
{
|
||||
return new TUserToken
|
||||
{
|
||||
UserId = user.Id,
|
||||
LoginProvider = loginProvider,
|
||||
Name = name,
|
||||
Value = value
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a flag indicating if changes should be persisted after CreateAsync, UpdateAsync and DeleteAsync are called.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
[
|
||||
{
|
||||
"OldTypeId": "public abstract class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, T4, T5, T6, T7> : Microsoft.AspNetCore.Identity.IUserLoginStore<T0>, Microsoft.AspNetCore.Identity.IUserRoleStore<T0>, Microsoft.AspNetCore.Identity.IUserClaimStore<T0>, Microsoft.AspNetCore.Identity.IUserPasswordStore<T0>, Microsoft.AspNetCore.Identity.IUserSecurityStampStore<T0>, Microsoft.AspNetCore.Identity.IUserEmailStore<T0>, Microsoft.AspNetCore.Identity.IUserLockoutStore<T0>, Microsoft.AspNetCore.Identity.IUserPhoneNumberStore<T0>, Microsoft.AspNetCore.Identity.IQueryableUserStore<T0>, Microsoft.AspNetCore.Identity.IUserTwoFactorStore<T0>, Microsoft.AspNetCore.Identity.IUserAuthenticationTokenStore<T0> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3, T4, T5, T6> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3, T5, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T3>> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3> where T4 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3> where T5 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3> where T6 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3> where T7 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T0, T1, T2, T3> where T0 : System.IEquatable<T0>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T0> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T0, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T0>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T0>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T0>> where T0 : System.IEquatable<T0>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public static class Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions",
|
||||
"OldMemberId": "public static new Microsoft.AspNetCore.Identity.IdentityBuilder AddEntityFrameworkStores<T0, T1>(this Microsoft.AspNetCore.Identity.IdentityBuilder builder) where T0 : Microsoft.EntityFrameworkCore.DbContext where T1 : System.IEquatable<T1>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public abstract class Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext<T0, T1, T2, T3, T4, T5, T6, T7> : Microsoft.EntityFrameworkCore.DbContext where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T2, T3, T4, T5> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T2, T4, T6> where T2 : System.IEquatable<T2> where T3 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T2> where T4 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T2> where T5 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T2> where T6 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T2> where T7 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T2>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3> CreateUserLogin(T0 user, Microsoft.AspNetCore.Identity.UserLoginInfo login)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3> CreateUserClaim(T0 user, System.Security.Claims.Claim claim)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3> CreateUserRole(T0 user, T1 role)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore<T0, T1, T2> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore<T0, T1, T2, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T2>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T2>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T2> where T1 : Microsoft.EntityFrameworkCore.DbContext where T2 : System.IEquatable<T2>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T2> CreateRoleClaim(T0 role, System.Security.Claims.Claim claim)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3> CreateUserToken(T0 user, System.String loginProvider, System.String name, System.String value)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public abstract class Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore<T0, T1, T2, T3, T4> : Microsoft.AspNetCore.Identity.IQueryableRoleStore<T0>, Microsoft.AspNetCore.Identity.IRoleClaimStore<T0> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T2, T3, T4> where T1 : Microsoft.EntityFrameworkCore.DbContext where T2 : System.IEquatable<T2> where T3 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T2> where T4 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T2>",
|
||||
"Kind": "Removal"
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
[
|
||||
{
|
||||
"OldTypeId": "public abstract class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, T4, T5, T6, T7> : Microsoft.AspNetCore.Identity.IUserLoginStore<T0>, Microsoft.AspNetCore.Identity.IUserRoleStore<T0>, Microsoft.AspNetCore.Identity.IUserClaimStore<T0>, Microsoft.AspNetCore.Identity.IUserPasswordStore<T0>, Microsoft.AspNetCore.Identity.IUserSecurityStampStore<T0>, Microsoft.AspNetCore.Identity.IUserEmailStore<T0>, Microsoft.AspNetCore.Identity.IUserLockoutStore<T0>, Microsoft.AspNetCore.Identity.IUserPhoneNumberStore<T0>, Microsoft.AspNetCore.Identity.IQueryableUserStore<T0>, Microsoft.AspNetCore.Identity.IUserTwoFactorStore<T0>, Microsoft.AspNetCore.Identity.IUserAuthenticationTokenStore<T0> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3, T4, T5, T6> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3, T5, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T3>> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3> where T4 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3> where T5 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3> where T6 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3> where T7 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T0, T1, T2, T3> where T0 : System.IEquatable<T0>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T0> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T0, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T0>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T0>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T0>> where T0 : System.IEquatable<T0>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public static class Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions",
|
||||
"OldMemberId": "public static new Microsoft.AspNetCore.Identity.IdentityBuilder AddEntityFrameworkStores<T0, T1>(this Microsoft.AspNetCore.Identity.IdentityBuilder builder) where T0 : Microsoft.EntityFrameworkCore.DbContext where T1 : System.IEquatable<T1>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public abstract class Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext<T0, T1, T2, T3, T4, T5, T6, T7> : Microsoft.EntityFrameworkCore.DbContext where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T2, T3, T4, T5> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T2, T4, T6> where T2 : System.IEquatable<T2> where T3 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T2> where T4 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T2> where T5 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T2> where T6 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T2> where T7 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T2>",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3> CreateUserLogin(T0 user, Microsoft.AspNetCore.Identity.UserLoginInfo login)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3> CreateUserClaim(T0 user, System.Security.Claims.Claim claim)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3> CreateUserRole(T0 user, T1 role)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore<T0, T1, T2> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore<T0, T1, T2, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T2>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T2>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T2> where T1 : Microsoft.EntityFrameworkCore.DbContext where T2 : System.IEquatable<T2>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T2> CreateRoleClaim(T0 role, System.Security.Claims.Claim claim)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public class Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3> : Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<T0, T1, T2, T3, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<T3>, Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3>> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser<T3> where T1 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T3> where T2 : Microsoft.EntityFrameworkCore.DbContext where T3 : System.IEquatable<T3>",
|
||||
"OldMemberId": "protected override Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<T3> CreateUserToken(T0 user, System.String loginProvider, System.String name, System.String value)",
|
||||
"Kind": "Removal"
|
||||
},
|
||||
{
|
||||
"OldTypeId": "public abstract class Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore<T0, T1, T2, T3, T4> : Microsoft.AspNetCore.Identity.IQueryableRoleStore<T0>, Microsoft.AspNetCore.Identity.IRoleClaimStore<T0> where T0 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole<T2, T3, T4> where T1 : Microsoft.EntityFrameworkCore.DbContext where T2 : System.IEquatable<T2> where T3 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<T2> where T4 : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<T2>",
|
||||
"Kind": "Removal"
|
||||
}
|
||||
]
|
||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
|
|||
}
|
||||
|
||||
public abstract class InMemoryContext<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken> : IdentityDbContext<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>
|
||||
where TUser : IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin>
|
||||
where TUser : IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>
|
||||
where TRole : IdentityRole<TKey, TUserRole, TRoleClaim>
|
||||
where TKey : IEquatable<TKey>
|
||||
where TUserClaim : IdentityUserClaim<TKey>
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
|
|||
|
||||
#region Generic Type defintions
|
||||
|
||||
public class IdentityUserWithGenerics : IdentityUser<string, IdentityUserClaimWithIssuer, IdentityUserRoleWithDate, IdentityUserLoginWithContext>
|
||||
public class IdentityUserWithGenerics : IdentityUser<string, IdentityUserClaimWithIssuer, IdentityUserRoleWithDate, IdentityUserLoginWithContext, IdentityUserTokenWithStuff>
|
||||
{
|
||||
public IdentityUserWithGenerics()
|
||||
{
|
||||
|
|
@ -196,7 +196,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
|
|||
}
|
||||
}
|
||||
|
||||
public class UserStoreWithGenerics : UserStore<IdentityUserWithGenerics, MyIdentityRole, InMemoryContextWithGenerics, string, IdentityUserClaimWithIssuer, IdentityUserRoleWithDate, IdentityUserLoginWithContext, IdentityUserTokenWithStuff>
|
||||
public class UserStoreWithGenerics : UserStore<IdentityUserWithGenerics, MyIdentityRole, InMemoryContextWithGenerics, string, IdentityUserClaimWithIssuer, IdentityUserRoleWithDate, IdentityUserLoginWithContext, IdentityUserTokenWithStuff, IdentityRoleClaimWithIssuer>
|
||||
{
|
||||
public string LoginContext { get; set; }
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
|
|||
}
|
||||
}
|
||||
|
||||
public class RoleStoreWithGenerics : RoleStore<MyIdentityRole, InMemoryContextWithGenerics, string, IdentityUserRoleWithDate, IdentityRoleClaim<string>>
|
||||
public class RoleStoreWithGenerics : RoleStore<MyIdentityRole, InMemoryContextWithGenerics, string, IdentityUserRoleWithDate, IdentityRoleClaimWithIssuer>
|
||||
{
|
||||
private string _loginContext;
|
||||
public RoleStoreWithGenerics(InMemoryContextWithGenerics context, string loginContext) : base(context)
|
||||
|
|
@ -253,10 +253,6 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
|
|||
_loginContext = loginContext;
|
||||
}
|
||||
|
||||
protected override IdentityRoleClaim<string> CreateRoleClaim(MyIdentityRole role, Claim claim)
|
||||
{
|
||||
return new IdentityRoleClaim<string> { RoleId = role.Id, ClaimType = claim.Type, ClaimValue = claim.Value };
|
||||
}
|
||||
}
|
||||
|
||||
public class IdentityUserClaimWithIssuer : IdentityUserClaim<string>
|
||||
|
|
@ -276,12 +272,29 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
|
|||
}
|
||||
}
|
||||
|
||||
public class IdentityRoleClaimWithIssuer : IdentityRoleClaim<string>
|
||||
{
|
||||
public string Issuer { get; set; }
|
||||
|
||||
public override Claim ToClaim()
|
||||
{
|
||||
return new Claim(ClaimType, ClaimValue, null, Issuer);
|
||||
}
|
||||
|
||||
public override void InitializeFromClaim(Claim other)
|
||||
{
|
||||
ClaimValue = other.Value;
|
||||
ClaimType = other.Type;
|
||||
Issuer = other.Issuer;
|
||||
}
|
||||
}
|
||||
|
||||
public class IdentityUserRoleWithDate : IdentityUserRole<string>
|
||||
{
|
||||
public DateTime Created { get; set; }
|
||||
}
|
||||
|
||||
public class MyIdentityRole : IdentityRole<string, IdentityUserRoleWithDate, IdentityRoleClaim<string>>
|
||||
public class MyIdentityRole : IdentityRole<string, IdentityUserRoleWithDate, IdentityRoleClaimWithIssuer>
|
||||
{
|
||||
public MyIdentityRole() : base()
|
||||
{
|
||||
|
|
@ -305,7 +318,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test
|
|||
public string Context { get; set; }
|
||||
}
|
||||
|
||||
public class InMemoryContextWithGenerics : InMemoryContext<IdentityUserWithGenerics, MyIdentityRole, string, IdentityUserClaimWithIssuer, IdentityUserRoleWithDate, IdentityUserLoginWithContext, IdentityRoleClaim<string>, IdentityUserTokenWithStuff>
|
||||
public class InMemoryContextWithGenerics : InMemoryContext<IdentityUserWithGenerics, MyIdentityRole, string, IdentityUserClaimWithIssuer, IdentityUserRoleWithDate, IdentityUserLoginWithContext, IdentityRoleClaimWithIssuer, IdentityUserTokenWithStuff>
|
||||
{
|
||||
public InMemoryContextWithGenerics(DbContextOptions options) : base(options)
|
||||
{ }
|
||||
|
|
|
|||
|
|
@ -218,6 +218,25 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
Assert.Equal(0, roles.Count());
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
||||
[OSSkipCondition(OperatingSystems.Linux)]
|
||||
[OSSkipCondition(OperatingSystems.MacOSX)]
|
||||
public async Task DeleteUserRemovesTokensTest()
|
||||
{
|
||||
// Need fail if not empty?
|
||||
var userMgr = CreateManager();
|
||||
var user = CreateTestUser();
|
||||
IdentityResultAssert.IsSuccess(await userMgr.CreateAsync(user));
|
||||
IdentityResultAssert.IsSuccess(await userMgr.SetAuthenticationTokenAsync(user, "provider", "test", "value"));
|
||||
|
||||
Assert.Equal("value", await userMgr.GetAuthenticationTokenAsync(user, "provider", "test"));
|
||||
|
||||
IdentityResultAssert.IsSuccess(await userMgr.DeleteAsync(user));
|
||||
|
||||
Assert.Null(await userMgr.GetAuthenticationTokenAsync(user, "provider", "test"));
|
||||
}
|
||||
|
||||
|
||||
[ConditionalFact]
|
||||
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
public void AddEntityFrameworkStoresWithInvalidUserThrows()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
var builder = services.AddIdentity<IdentityUserWithGenerics, IdentityRole>();
|
||||
var builder = services.AddIdentity<object, IdentityRole>();
|
||||
var e = Assert.Throws<InvalidOperationException>(() => builder.AddEntityFrameworkStores<ContextWithGenerics>());
|
||||
Assert.Contains("AddEntityFrameworkStores", e.Message);
|
||||
}
|
||||
|
|
@ -96,11 +96,20 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
public void AddEntityFrameworkStoresWithInvalidRoleThrows()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
var builder = services.AddIdentity<IdentityUser, MyIdentityRole>();
|
||||
var builder = services.AddIdentity<IdentityUser, object>();
|
||||
var e = Assert.Throws<InvalidOperationException>(() => builder.AddEntityFrameworkStores<ContextWithGenerics>());
|
||||
Assert.Contains("AddEntityFrameworkStores", e.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddEntityFrameworkStoresWithMismatchedUserRoleThrows()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
var builder = services.AddIdentity<IdentityUserWithGenerics, IdentityRole>();
|
||||
var e = Assert.Throws<ArgumentException>(() => builder.AddEntityFrameworkStores<ContextWithGenerics>());
|
||||
Assert.Contains("violates the constraint of type 'TRole'", e.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CanAddRemoveUserClaimWithIssuer()
|
||||
{
|
||||
|
|
@ -209,7 +218,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
|
||||
#region Generic Type defintions
|
||||
|
||||
public class IdentityUserWithGenerics : IdentityUser<string, IdentityUserClaimWithIssuer, IdentityUserRoleWithDate, IdentityUserLoginWithContext>
|
||||
public class IdentityUserWithGenerics : IdentityUser<string, IdentityUserClaimWithIssuer, IdentityUserRoleWithDate, IdentityUserLoginWithContext, IdentityUserTokenWithStuff>
|
||||
{
|
||||
public IdentityUserWithGenerics()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue