Refractor token auth stuff to use identiycore framework
This commit is contained in:
parent
f8d7581a12
commit
8f7df85d49
14 changed files with 377 additions and 50 deletions
|
|
@ -1,17 +1,36 @@
|
|||
using System;
|
||||
using API.Entities;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Data
|
||||
{
|
||||
public class DataContext : DbContext
|
||||
public class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
||||
IdentityUserClaim<int>, AppUserRole, IdentityUserLogin<int>,
|
||||
IdentityRoleClaim<int>, IdentityUserToken<int>>
|
||||
{
|
||||
public DataContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DbSet<AppUser> Users { get; set; }
|
||||
public DbSet<Library> Library { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.Entity<AppUser>()
|
||||
.HasMany(ur => ur.UserRoles)
|
||||
.WithOne(u => u.User)
|
||||
.HasForeignKey(ur => ur.UserId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Entity<AppRole>()
|
||||
.HasMany(ur => ur.UserRoles)
|
||||
.WithOne(u => u.Role)
|
||||
.HasForeignKey(ur => ur.RoleId)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue