|
- using System;
- using System.Collections.Generic;
- using SUISS.Storage;
-
- namespace SUISS.Cloud
- {
- public class AccessToken : IAccessToken, IStorable
- {
- public AccessToken()
- {
- this.Token = string.Empty;
- this.Scope = string.Empty;
- this.Expires = DateTime.MinValue;
- }
-
- public AccessToken(string token, string scope, DateTime expires)
- {
- this.Token = token;
- this.Scope = scope;
- this.Expires = expires;
- }
-
- public string Scope { get; private set; }
-
- public DateTime Expires { get; private set; }
-
- public string Token { get; private set; }
-
- public bool HasExpired
- {
- get
- {
- return string.IsNullOrEmpty(this.Token) || this.Expires <= DateTime.UtcNow.AddSeconds(30.0);
- }
- }
-
- [Obsolete("Use HasExpired")]
- public bool hasExpired
- {
- get
- {
- return this.HasExpired;
- }
- }
-
- public void Invalidate()
- {
- this.Expires = DateTime.MinValue;
- this.Scope = string.Empty;
- this.Token = string.Empty;
- }
-
- void IStorable.FromStorage(IDictionary<string, object> dict)
- {
- if (dict.ContainsKey("scope"))
- {
- this.Scope = (string)dict["scope"];
- }
- if (dict.ContainsKey("token"))
- {
- this.Token = (string)dict["token"];
- }
- if (dict.ContainsKey("expires"))
- {
- this.Expires = new DateTime((long)dict["expires"]);
- }
- }
-
- IDictionary<string, object> IStorable.ToStorage()
- {
- Dictionary<string, object> dictionary = new Dictionary<string, object>();
- dictionary["scope"] = this.Scope;
- dictionary["token"] = this.Token;
- dictionary["expires"] = this.Expires.Ticks;
- return dictionary;
- }
-
- private const string ScopeKey = "scope";
-
- private const string TokenKey = "token";
-
- private const string ExpiresKey = "expires";
- }
- }
|