12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Dfs.WayneChina.SpsDataCourier
- {
- public class AuthToken
- {
- #region Standard OAuth token format
- /// <summary>
- /// The access token string issued by the authorization server.
- /// </summary>
- [JsonProperty("access_token")]
- public string AccessToken { get; set; }
- /// <summary>
- /// Token type, simply `bearer`.
- /// </summary>
- [JsonProperty("token_type")]
- public string TokenType { get; set; }
- /// <summary>
- /// Duration of the time the access token is granted for, in total seconds.
- /// </summary>
- [JsonProperty("expires_in")]
- public int ExpiresIn { get; set; }
- /// <summary>
- /// Access token to be used to get a new token, optional.
- /// </summary>
- [JsonProperty("refresh_token")]
- public string RefreshToken { get; set; }
- /// <summary>
- /// The error information
- /// </summary>
- [JsonProperty("error")]
- public string Error { get; set; }
- #endregion
- #region Custom extension
- /// <summary>
- /// When the token is retrieve from the auth server, to simplify, set the local received time.
- /// </summary>
- public DateTime TokenRetrievedTime { get; set; }
- /// <summary>
- /// Check if the token has expired or not, if not, then it's valid.
- /// </summary>
- /// <returns>valid or not</returns>
- 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
- }
- }
|