添加OAuth2认证相关配置文件和服务实现,包括环境变量配置、PKCE流程支持、token管理等功能。主要变更: - 新增OAuth2配置文件 - 实现OAuth2服务层 - 更新请求拦截器支持token自动刷新 - 修改认证API和store以支持OAuth2流程
89 lines
3.7 KiB
C#
89 lines
3.7 KiB
C#
using Fengling.AuthService.Models;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Fengling.AuthService.Data;
|
|
|
|
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, long>
|
|
{
|
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public DbSet<Tenant> Tenants { get; set; }
|
|
public DbSet<AccessLog> AccessLogs { get; set; }
|
|
public DbSet<AuditLog> AuditLogs { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
base.OnModelCreating(builder);
|
|
|
|
builder.Entity<ApplicationUser>(entity =>
|
|
{
|
|
entity.Property(e => e.RealName).HasMaxLength(100);
|
|
entity.Property(e => e.Phone).HasMaxLength(20);
|
|
entity.HasIndex(e => e.Phone).IsUnique();
|
|
|
|
entity.OwnsOne(e => e.TenantInfo, navigationBuilder =>
|
|
{
|
|
navigationBuilder.Property(e => e.Id).HasColumnName("TenantId");
|
|
navigationBuilder.Property(e => e.TenantId).HasColumnName("TenantCode");
|
|
navigationBuilder.Property(e => e.Name).HasColumnName("TenantName");
|
|
navigationBuilder.WithOwner();
|
|
});
|
|
});
|
|
|
|
builder.Entity<ApplicationRole>(entity => { entity.Property(e => e.Description).HasMaxLength(200); });
|
|
|
|
builder.Entity<Tenant>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.HasIndex(e => e.TenantId).IsUnique();
|
|
entity.Property(e => e.TenantId).HasMaxLength(50);
|
|
entity.Property(e => e.Name).HasMaxLength(100);
|
|
entity.Property(e => e.ContactName).HasMaxLength(50);
|
|
entity.Property(e => e.ContactEmail).HasMaxLength(100);
|
|
entity.Property(e => e.ContactPhone).HasMaxLength(20);
|
|
entity.Property(e => e.Status).HasMaxLength(20);
|
|
entity.Property(e => e.Description).HasMaxLength(500);
|
|
});
|
|
|
|
builder.Entity<AccessLog>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.HasIndex(e => e.CreatedAt);
|
|
entity.HasIndex(e => e.UserName);
|
|
entity.HasIndex(e => e.TenantId);
|
|
entity.HasIndex(e => e.Action);
|
|
entity.HasIndex(e => e.Status);
|
|
entity.Property(e => e.UserName).HasMaxLength(50);
|
|
entity.Property(e => e.TenantId).HasMaxLength(50);
|
|
entity.Property(e => e.Action).HasMaxLength(20);
|
|
entity.Property(e => e.Resource).HasMaxLength(200);
|
|
entity.Property(e => e.Method).HasMaxLength(10);
|
|
entity.Property(e => e.IpAddress).HasMaxLength(50);
|
|
entity.Property(e => e.UserAgent).HasMaxLength(500);
|
|
entity.Property(e => e.Status).HasMaxLength(20);
|
|
});
|
|
|
|
builder.Entity<AuditLog>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.HasIndex(e => e.CreatedAt);
|
|
entity.HasIndex(e => e.Operator);
|
|
entity.HasIndex(e => e.TenantId);
|
|
entity.HasIndex(e => e.Operation);
|
|
entity.HasIndex(e => e.Action);
|
|
entity.Property(e => e.Operator).HasMaxLength(50);
|
|
entity.Property(e => e.TenantId).HasMaxLength(50);
|
|
entity.Property(e => e.Operation).HasMaxLength(20);
|
|
entity.Property(e => e.Action).HasMaxLength(20);
|
|
entity.Property(e => e.TargetType).HasMaxLength(50);
|
|
entity.Property(e => e.TargetName).HasMaxLength(100);
|
|
entity.Property(e => e.IpAddress).HasMaxLength(50);
|
|
entity.Property(e => e.Description).HasMaxLength(500);
|
|
entity.Property(e => e.Status).HasMaxLength(20);
|
|
});
|
|
}
|
|
} |