private async Task FetchOidcConfigurationAsync()

in wwauth/Google.Solutions.WWAuth/Adapters/Adfs/AdfsOidcAdapter.cs [76:121]


        private async Task<OidcConfiguration> FetchOidcConfigurationAsync(
            CancellationToken cancellationToken)
        {
            try
            {
                this.Logger.Info(
                    "Fetching OpenID Connect configuration from '{0}'",
                    this.OidcConfigurationUrl);

                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.UserAgent.Add(
                        new ProductInfoHeaderValue(
                            UserAgent.Default.Name,
                            UserAgent.Default.Version));
                    using (var response = await client.GetAsync(
                            this.OidcConfigurationUrl,
                            cancellationToken)
                        .ConfigureAwait(false))
                    {
                        response.EnsureSuccessStatusCode();

                        return JsonConvert.DeserializeObject<OidcConfiguration>(
                            await response.Content
                                .ReadAsStringAsync()
                                .ConfigureAwait(false));
                    }
                }
            }
            catch (JsonException e)
            {
                throw new TokenAcquisitionException(
                    $"The OpenID Connect configuration located at '{this.OidcConfigurationUrl}' " +
                    $"contains invalid data. Verify that the issuer URL '{this.IssuerUrl}' " +
                    "is correct and that the URL is accessible.",
                    e);
            }
            catch (HttpRequestException e)
            {
                throw new TokenAcquisitionException(
                    $"The OpenID Connect configuration located at '{this.OidcConfigurationUrl}' " +
                    $"is not available. Verify that the issuer URL '{this.IssuerUrl}' " +
                    "is correct and that the URL is accessible.",
                    e);
            }
        }