您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 

85 行
1.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using SUISS.Storage;
  4. namespace SUISS.Cloud
  5. {
  6. public class AccessToken : IAccessToken, IStorable
  7. {
  8. public AccessToken()
  9. {
  10. this.Token = string.Empty;
  11. this.Scope = string.Empty;
  12. this.Expires = DateTime.MinValue;
  13. }
  14. public AccessToken(string token, string scope, DateTime expires)
  15. {
  16. this.Token = token;
  17. this.Scope = scope;
  18. this.Expires = expires;
  19. }
  20. public string Scope { get; private set; }
  21. public DateTime Expires { get; private set; }
  22. public string Token { get; private set; }
  23. public bool HasExpired
  24. {
  25. get
  26. {
  27. return string.IsNullOrEmpty(this.Token) || this.Expires <= DateTime.UtcNow.AddSeconds(30.0);
  28. }
  29. }
  30. [Obsolete("Use HasExpired")]
  31. public bool hasExpired
  32. {
  33. get
  34. {
  35. return this.HasExpired;
  36. }
  37. }
  38. public void Invalidate()
  39. {
  40. this.Expires = DateTime.MinValue;
  41. this.Scope = string.Empty;
  42. this.Token = string.Empty;
  43. }
  44. void IStorable.FromStorage(IDictionary<string, object> dict)
  45. {
  46. if (dict.ContainsKey("scope"))
  47. {
  48. this.Scope = (string)dict["scope"];
  49. }
  50. if (dict.ContainsKey("token"))
  51. {
  52. this.Token = (string)dict["token"];
  53. }
  54. if (dict.ContainsKey("expires"))
  55. {
  56. this.Expires = new DateTime((long)dict["expires"]);
  57. }
  58. }
  59. IDictionary<string, object> IStorable.ToStorage()
  60. {
  61. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  62. dictionary["scope"] = this.Scope;
  63. dictionary["token"] = this.Token;
  64. dictionary["expires"] = this.Expires.Ticks;
  65. return dictionary;
  66. }
  67. private const string ScopeKey = "scope";
  68. private const string TokenKey = "token";
  69. private const string ExpiresKey = "expires";
  70. }
  71. }