-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccessToken.cs
29 lines (24 loc) · 927 Bytes
/
AccessToken.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System.Text.Json.Serialization;
namespace NetSuiteRestApiOAuth2
{
internal class AccessToken
{
private static readonly TimeSpan _expirеThreshold = new(0, 5, 0);
public AccessToken(string tokenType, string token, int expiresIn)
{
TokenType = tokenType;
Token = token;
ExpiresIn = expiresIn;
ExpiresAt = DateTime.UtcNow.AddSeconds(ExpiresIn);
}
[JsonPropertyName("token_type")]
public string TokenType { get; }
[JsonPropertyName("access_token")]
public string Token { get; }
[JsonPropertyName("expires_in")]
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public int ExpiresIn { get; }
public DateTime ExpiresAt { get; }
public bool IsAboutToExpire => (ExpiresAt - DateTime.UtcNow).TotalSeconds <= _expirеThreshold.TotalSeconds;
}
}