- 新增 API 端 JWT 登录、refresh token 轮换和退出登录流程 - 新增 refresh token 实体、DbSet 配置和 EF Core 迁移 - 新增 PC 端授权码登录、本地全局 token 刷新、登出和鉴权服务 - 扩展统一端点模型,支持宿主过滤、角色鉴权、OpenAPI 元数据和 DI 服务处理器 - API 启用 JwtBearer 认证、Swagger UI 和认证端点注册 - PC 端注册认证服务,并按宿主过滤桌面拦截端点
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using Avalonia_EFCore.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Avalonia_EFCore.Database
|
|
{
|
|
/// <summary>
|
|
/// 应用数据库上下文 —— 继承自 Avalonia-EFCore 的 AppDbContext。
|
|
/// 所有业务实体在此注册 DbSet。
|
|
/// 这是 Avalonia-API 和 Avalonia-PC 共用的具体数据上下文。
|
|
/// </summary>
|
|
public class AppDataContext(DatabaseConfiguration dbConfig) : AppDbContext(dbConfig)
|
|
{
|
|
/// <summary>天气预报数据</summary>
|
|
public DbSet<WeatherForecastEntity> WeatherForecasts => Set<WeatherForecastEntity>();
|
|
|
|
/// <summary>用户数据</summary>
|
|
public DbSet<UserEntity> Users => Set<UserEntity>();
|
|
|
|
/// <summary>API refresh token 数据</summary>
|
|
public DbSet<ApiRefreshTokenEntity> ApiRefreshTokens => Set<ApiRefreshTokenEntity>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<WeatherForecastEntity>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("pk-weather-forecast");
|
|
entity.Property(e => e.Summary).HasMaxLength(200);
|
|
});
|
|
|
|
modelBuilder.Entity<UserEntity>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("pk-user");
|
|
entity.Property(e => e.Email).HasMaxLength(200);
|
|
});
|
|
|
|
modelBuilder.Entity<ApiRefreshTokenEntity>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("pk-api-refresh-token");
|
|
entity.HasIndex(e => e.TokenHash).IsUnique().HasDatabaseName("idx-api-refresh-token-hash");
|
|
entity.HasIndex(e => e.UserId).HasDatabaseName("idx-api-refresh-token-user-id");
|
|
});
|
|
}
|
|
}
|
|
}
|