public static void SaveCache(Dictionary <string, TenantCacheInfo> cache) { var file = GetCacheFile(); var json = JObject.FromObject(cache); ProtectedFile.WriteAllText(file, json.ToString()); }
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()); }
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); }
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))); }
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)); }
public static void SaveRecentToken(AuthenticationResult authResult) { ProtectedFile.WriteAllText(GetRecentTokenFile(), authResult.Serialize()); }