Beispiel #1
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);
        }
Beispiel #2
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)));
        }
Beispiel #3
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));
        }