| | | 1 | | namespace KT.Modules.Security.Core.Domain |
| | | 2 | | { |
| | | 3 | | internal class RefreshToken |
| | | 4 | | { |
| | 21 | 5 | | public RefreshToken(string id, string token, string userId, DateTime expires) |
| | 21 | 6 | | { |
| | 21 | 7 | | if (string.IsNullOrWhiteSpace(id)) |
| | 2 | 8 | | throw new ArgumentException("The identifier cannot be empty.", nameof(id)); |
| | | 9 | | |
| | 19 | 10 | | if (string.IsNullOrWhiteSpace(token)) |
| | 2 | 11 | | throw new ArgumentException("The token cannot be empty.", nameof(token)); |
| | | 12 | | |
| | 17 | 13 | | if (string.IsNullOrWhiteSpace(userId)) |
| | 2 | 14 | | throw new ArgumentException("The user identifier cannot be empty.", nameof(userId)); |
| | | 15 | | |
| | 15 | 16 | | if (expires <= DateTime.UtcNow) |
| | 1 | 17 | | throw new ArgumentException("The expiration date must be in the future.", nameof(expires)); |
| | | 18 | | |
| | 14 | 19 | | Id = id; |
| | 14 | 20 | | Token = token; |
| | 14 | 21 | | UserId = userId; |
| | 14 | 22 | | Expires = expires; |
| | 14 | 23 | | IsRevoked = false; |
| | 14 | 24 | | } |
| | | 25 | | |
| | 14 | 26 | | public string Id { get; private set; } |
| | 19 | 27 | | public string Token { get; private set; } |
| | 18 | 28 | | public string UserId { get; private set; } |
| | 26 | 29 | | public DateTime Expires { get; private set; } |
| | 39 | 30 | | public bool IsRevoked { get; private set; } |
| | | 31 | | |
| | 4 | 32 | | public bool IsExpired => DateTime.UtcNow >= Expires; |
| | 4 | 33 | | public bool IsActive => !IsRevoked && !IsExpired; |
| | | 34 | | |
| | | 35 | | public void Revoke() |
| | 7 | 36 | | { |
| | 7 | 37 | | if (IsRevoked) |
| | 1 | 38 | | throw new InvalidOperationException("The token has already been revoked."); |
| | | 39 | | |
| | 6 | 40 | | IsRevoked = true; |
| | 6 | 41 | | } |
| | | 42 | | } |
| | | 43 | | } |