using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Text; namespace Dfs.WayneChina.SpsDataCourier { public class AuthToken { #region Standard OAuth token format /// /// The access token string issued by the authorization server. /// [JsonProperty("access_token")] public string AccessToken { get; set; } /// /// Token type, simply `bearer`. /// [JsonProperty("token_type")] public string TokenType { get; set; } /// /// Duration of the time the access token is granted for, in total seconds. /// [JsonProperty("expires_in")] public int ExpiresIn { get; set; } /// /// Access token to be used to get a new token, optional. /// [JsonProperty("refresh_token")] public string RefreshToken { get; set; } /// /// The error information /// [JsonProperty("error")] public string Error { get; set; } #endregion #region Custom extension /// /// When the token is retrieve from the auth server, to simplify, set the local received time. /// public DateTime TokenRetrievedTime { get; set; } /// /// Check if the token has expired or not, if not, then it's valid. /// /// valid or not public bool IsTokenValid() { //Current Time = Now + 5 minutes, Expiry Time = token retrieved time + expiry time span //If current time is not later than expiry time, then the token is valid if (DateTime.Now + new TimeSpan(0, 5, 0) < TokenRetrievedTime + new TimeSpan(0, 0, ExpiresIn)) return true; return false; } #endregion } }