internal async Task StoreToCacheAsync(AuthenticationResultEx result, string authority, string resource, string clientId,
                                              TokenSubjectType subjectType, CallState callState)
        {
            var metadata = await InstanceDiscovery.GetMetadataEntryAsync(new Uri(authority), false, callState).ConfigureAwait(false);

            StoreToCacheCommon(result, ReplaceHost(authority, metadata.PreferredCache), resource, clientId, subjectType, callState);
        }
        internal static async Task <List <string> > GetOrderedAliasesAsync(string authority, bool validateAuthority, CallState callState)
        {
            var metadata = await InstanceDiscovery.GetMetadataEntryAsync(new Uri(authority), validateAuthority, callState).ConfigureAwait(false);

            var aliasedAuthorities = new List <string>(new string[] { metadata.PreferredCache, GetHost(authority) });

            aliasedAuthorities.AddRange(metadata.Aliases ?? Enumerable.Empty <string>());
            return(aliasedAuthorities);
        }