50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
|
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
using System.ComponentModel.DataAnnotations;
|
|||
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
|
|
|||
|
|
namespace Avalonia_EFCore.Models
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// API refresh token。只保存哈希,不保存明文 token。
|
|||
|
|
/// </summary>
|
|||
|
|
[Comment("API refresh token")]
|
|||
|
|
[Table("api-refresh-token")]
|
|||
|
|
public class ApiRefreshTokenEntity
|
|||
|
|
{
|
|||
|
|
[Key]
|
|||
|
|
[Column("id")]
|
|||
|
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|||
|
|
public long Id { get; set; }
|
|||
|
|
|
|||
|
|
[Column("user-id")]
|
|||
|
|
public int UserId { get; set; }
|
|||
|
|
|
|||
|
|
[Column("token-hash")]
|
|||
|
|
[MaxLength(128)]
|
|||
|
|
public string TokenHash { get; set; } = string.Empty;
|
|||
|
|
|
|||
|
|
[Column("created-at")]
|
|||
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|||
|
|
|
|||
|
|
[Column("expires-at")]
|
|||
|
|
public DateTime ExpiresAt { get; set; }
|
|||
|
|
|
|||
|
|
[Column("revoked-at")]
|
|||
|
|
public DateTime? RevokedAt { get; set; }
|
|||
|
|
|
|||
|
|
[Column("replaced-by-token-hash")]
|
|||
|
|
[MaxLength(128)]
|
|||
|
|
public string? ReplacedByTokenHash { get; set; }
|
|||
|
|
|
|||
|
|
[Column("device")]
|
|||
|
|
[MaxLength(200)]
|
|||
|
|
public string? Device { get; set; }
|
|||
|
|
|
|||
|
|
[Column("ip-address")]
|
|||
|
|
[MaxLength(64)]
|
|||
|
|
public string? IpAddress { get; set; }
|
|||
|
|
|
|||
|
|
public bool IsActive => RevokedAt is null && ExpiresAt > DateTime.UtcNow;
|
|||
|
|
}
|
|||
|
|
}
|