/// <summary> /// WARNING: if partitonKey = null, this API is slow as it loads all tokens, not just from 1 partition. /// It should only support external token caching, in the hope that the external token cache is partitioned. /// </summary> public virtual List <MsalAccessTokenCacheItem> GetAllAccessTokens(string partitionKey = null, ICoreLogger requestlogger = null) { ICoreLogger logger = requestlogger ?? _logger; logger.Always($"[GetAllAccessTokens] Total number of cache partitions found while getting access tokens: {AccessTokenCacheDictionary.Count}"); if (string.IsNullOrEmpty(partitionKey)) { return(AccessTokenCacheDictionary.SelectMany(dict => dict.Value).Select(kv => kv.Value).ToList()); } else { AccessTokenCacheDictionary.TryGetValue(partitionKey, out ConcurrentDictionary <string, MsalAccessTokenCacheItem> partition); return(partition?.Select(kv => kv.Value)?.ToList() ?? CollectionHelpers.GetEmptyList <MsalAccessTokenCacheItem>()); } }
private static void LogMetricsFromAuthResult(AuthenticationResult authenticationResult, ICoreLogger logger) { var sb = new StringBuilder(250); sb.AppendLine(); sb.Append("[LogMetricsFromAuthResult] Cache Refresh Reason: "); sb.AppendLine(authenticationResult.AuthenticationResultMetadata.CacheRefreshReason.ToString()); sb.Append("[LogMetricsFromAuthResult] DurationInCacheInMs: "); sb.AppendLine(authenticationResult.AuthenticationResultMetadata.DurationInCacheInMs.ToString()); sb.Append("[LogMetricsFromAuthResult] DurationTotalInMs: "); sb.AppendLine(authenticationResult.AuthenticationResultMetadata.DurationTotalInMs.ToString()); sb.Append("[LogMetricsFromAuthResult] DurationInHttpInMs: "); sb.AppendLine(authenticationResult.AuthenticationResultMetadata.DurationInHttpInMs.ToString()); logger.Always(sb.ToString()); logger.AlwaysPii($"[LogMetricsFromAuthResult] TokenEndpoint: {authenticationResult.AuthenticationResultMetadata.TokenEndpoint ?? ""}", "TokenEndpoint: ****"); }