So my system requires that Roles have associated Expiry dates. I have implemented the Identity 2.0 framework, and things are going smoothly, but I've run into an issue that is making me doubt my structure.
public class ApplicationUserRole : IdentityUserRole
{
public override string UserId { get; set; }
public override string RoleId { get; set; }
public DateTime Expiry { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
static ApplicationDbContext()
{
Database.SetInitializer<ApplicationDbContext>(null);
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public DbSet<ApplicationUserRole> ApplicationUserRoles { get; set; }
}
This does what I want it to. It changes the AspNetUserRoles table so that it adds a third column which is a DateTime called Expiry. I'm able to add, update, and remove expiries using the ApplicationDBContext, all works fine and well while editing Users.
The issue arises on Account Creation. The UserManager calls AddToRolesAsync, but only takes two parameters, User and Role. I need it to take User, Role, and an Expiry.
Do I need to implement my own UserManager? That seems like overkill.
I'm able to get around the issue by not allowing role/expiry selection on account creation, and just leaving it to edit mode. But I'd really like to be able to create accounts and assign roles/expiries at the same time.