2026-05-21 15:52:36 +08:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
|
|
2026-05-22 14:29:22 +08:00
|
|
|
|
namespace FileShare_EFCore.Models
|
2026-05-21 15:52:36 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// API refresh token。只保存哈希,不保存明文 token。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Comment("API refresh token")]
|
|
|
|
|
|
[Table("api-refresh-token")]
|
|
|
|
|
|
public class ApiRefreshTokenEntity
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置主键 ID(自增)。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Key]
|
|
|
|
|
|
[Column("id")]
|
|
|
|
|
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
|
|
|
|
public long Id { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置关联的用户 ID。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Column("user-id")]
|
|
|
|
|
|
public int UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置 Token 的 SHA256 哈希值,用于安全存储和查询。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Column("token-hash")]
|
|
|
|
|
|
[MaxLength(128)]
|
|
|
|
|
|
public string TokenHash { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置 Token 创建时间。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Column("created-at")]
|
|
|
|
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置 Token 过期时间。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Column("expires-at")]
|
|
|
|
|
|
public DateTime ExpiresAt { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置 Token 撤销时间,null 表示尚未撤销。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Column("revoked-at")]
|
|
|
|
|
|
public DateTime? RevokedAt { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置替换此 Token 的新 Token 哈希值(轮换时设置)。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Column("replaced-by-token-hash")]
|
|
|
|
|
|
[MaxLength(128)]
|
|
|
|
|
|
public string? ReplacedByTokenHash { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置创建设备标识(如 User-Agent)。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Column("device")]
|
|
|
|
|
|
[MaxLength(200)]
|
|
|
|
|
|
public string? Device { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置创建时的客户端 IP 地址。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Column("ip-address")]
|
|
|
|
|
|
[MaxLength(64)]
|
|
|
|
|
|
public string? IpAddress { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取 Token 是否有效(未被撤销且未过期)。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsActive => RevokedAt is null && ExpiresAt > DateTime.UtcNow;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|