daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.     "access_token": "xxx",
  3.     "token_type": "bearer",
  4.     "expires_in": 86400,
  5.     "refresh_token": "yyy",
  6.     "created_at": 1524344276
  7. }
  8.    
  9. public class OAuth2Token
  10. {
  11.     [JsonProperty("access_token")]
  12.     public string AccessToken  { get; }
  13.  
  14.     [JsonProperty("token_type")]
  15.     public string TokenType    { get; }
  16.  
  17.     [JsonProperty("expires_in")]
  18.     public int    ExpiresIn    { get; } //Seconds
  19.  
  20.     [JsonProperty("refresh_token")]
  21.     public string RefreshToken { get; }
  22.  
  23.     [JsonProperty("created_at"), JsonConverter(typeof(SecondEpochConverter))]
  24.     public DateTime CreatedAt { get; }
  25. }
  26.    
  27. public class SecondEpochConverter : DateTimeConverterBase
  28. {
  29.     private static readonly DateTime _epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  30.  
  31.     public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
  32.     {
  33.         writer.WriteRawValue(((DateTime)value - _epoch).TotalSeconds.ToString());
  34.     }
  35.  
  36.     public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  37.     {
  38.         if (reader.Value == null) { return null; }
  39.         return _epoch.AddSeconds((long)reader.Value);
  40.     }
  41. }
RAW Paste Data
Top