<commit_before>﻿using IdentityModel.Jwk;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace IdentityModel.Client
{
    public class DiscoveryClient
    {
        private readonly HttpClient _client;

        public string Url { get; }

        public TimeSpan Timeout
        {
            set
            {
                _client.Timeout = value;
            }
        }

        public DiscoveryClient(string url, HttpMessageHandler innerHandler = null)
        {
            var handler = innerHandler ?? new HttpClientHandler();

            url = url.RemoveTrailingSlash();
            if (!url.EndsWith(OidcConstants.Discovery.DiscoveryEndpoint, StringComparison.OrdinalIgnoreCase))
            {
                url = url.EnsureTrailingSlash();
                url = url + OidcConstants.Discovery.DiscoveryEndpoint;
            }

            Url = url;

            _client = new HttpClient(handler);
        }

        public async Task<DiscoveryResponse> GetAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            var response = await _client.GetAsync(Url, cancellationToken).ConfigureAwait(false);
            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                var disco = new DiscoveryResponse(json);

                var jwkUrl = disco.JwksUri;
                if (jwkUrl != null)
                {
                    response = await _client.GetAsync(jwkUrl).ConfigureAwait(false);
                    if (response.IsSuccessStatusCode)
                    {
                        var jwk = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                        disco.Keys = new JsonWebKeySet(jwk);
                    }
                    else
                    {
                        return new DiscoveryResponse(response.StatusCode, response.ReasonPhrase);
                    }
                }

                return disco;
            }
            else
            {
                return new DiscoveryResponse(response.StatusCode, response.ReasonPhrase);
            }
        }
    }
}<commit_msg>add "quick access" method to discovery client<commit_after>﻿using IdentityModel.Jwk;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace IdentityModel.Client
{
    public class DiscoveryClient
    {
        public static async Task<DiscoveryResponse> GetAsync(string url)
        {
            var client = new DiscoveryClient(url);
            return await client.GetAsync();
        }

        private readonly HttpClient _client;

        public string Url { get; }

        public TimeSpan Timeout
        {
            set
            {
                _client.Timeout = value;
            }
        }

        public DiscoveryClient(string url, HttpMessageHandler innerHandler = null)
        {
            var handler = innerHandler ?? new HttpClientHandler();

            url = url.RemoveTrailingSlash();
            if (!url.EndsWith(OidcConstants.Discovery.DiscoveryEndpoint, StringComparison.OrdinalIgnoreCase))
            {
                url = url.EnsureTrailingSlash();
                url = url + OidcConstants.Discovery.DiscoveryEndpoint;
            }

            Url = url;

            _client = new HttpClient(handler);
        }

        public async Task<DiscoveryResponse> GetAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            var response = await _client.GetAsync(Url, cancellationToken).ConfigureAwait(false);
            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                var disco = new DiscoveryResponse(json);

                var jwkUrl = disco.JwksUri;
                if (jwkUrl != null)
                {
                    response = await _client.GetAsync(jwkUrl).ConfigureAwait(false);
                    if (response.IsSuccessStatusCode)
                    {
                        var jwk = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                        disco.Keys = new JsonWebKeySet(jwk);
                    }
                    else
                    {
                        return new DiscoveryResponse(response.StatusCode, response.ReasonPhrase);
                    }
                }

                return disco;
            }
            else
            {
                return new DiscoveryResponse(response.StatusCode, response.ReasonPhrase);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.0734139613834076, 'fraction_numerical': 0.0, 'mean_word_length': 1.5550135501355014, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3509969', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1104, 'n_words': 231}