示例#1
0
        public static void SaveCache(Dictionary <string, TenantCacheInfo> cache)
        {
            var file = GetCacheFile();
            var json = JObject.FromObject(cache);

            ProtectedFile.WriteAllText(file, json.ToString());
        }
示例#2
0
        public static void SaveCache(Dictionary <TokenCacheKey, string> cache)
        {
            var file = GetCacheFile();
            var dict = cache.ToDictionary(p => p.Value, p => p.Key);
            var json = JObject.FromObject(dict);

            ProtectedFile.WriteAllText(file, json.ToString());
        }
示例#3
0
        public static async Task <AuthenticationResult> GetRecentToken()
        {
            var recentTokenFile = GetRecentTokenFile();
            var authResult      = AuthenticationResult.Deserialize(ProtectedFile.ReadAllText(recentTokenFile));

            if (!String.IsNullOrEmpty(authResult.RefreshToken) && authResult.ExpiresOn <= DateTime.UtcNow)
            {
                var tokenCache = TokenCache.GetCache();
                authResult = await GetAuthorizationResult(tokenCache, authResult.TenantId, authResult.UserInfo.UserId);

                TokenCache.SaveCache(tokenCache);
                SaveRecentToken(authResult);
            }

            return(authResult);
        }
示例#4
0
        public static Dictionary <string, TenantCacheInfo> GetCache()
        {
            var file = GetCacheFile();

            if (!File.Exists(file))
            {
                return(new Dictionary <string, TenantCacheInfo>());
            }

            return(JsonConvert.DeserializeObject <Dictionary <string, TenantCacheInfo> >(ProtectedFile.ReadAllText(file)));
        }
示例#5
0
        public static Dictionary <TokenCacheKey, string> GetCache()
        {
            var file = GetCacheFile();

            if (!File.Exists(file))
            {
                return(new Dictionary <TokenCacheKey, string>());
            }

            var dict = JsonConvert.DeserializeObject <Dictionary <string, TokenCacheKey> >(ProtectedFile.ReadAllText(file));

            return(dict.ToDictionary(p => p.Value, p => p.Key));
        }
示例#6
0
 public static void SaveRecentToken(AuthenticationResult authResult)
 {
     ProtectedFile.WriteAllText(GetRecentTokenFile(), authResult.Serialize());
 }