/// <summary>
        /// Use client certificate for authenticating against the BankID API from Azure Key Vault.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="options">The Key Vault options.</param>
        /// <returns></returns>
        public static IBankIdBuilder UseClientCertificateFromAzureKeyVault(this IBankIdBuilder builder, ClientCertificateFromAzureKeyVaultOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.AzureKeyVaultSecretName))
            {
                throw new ArgumentException("AzureKeyVaultSecretName is required");
            }

            builder.UseClientCertificate(() =>
            {
                var keyVaultCertificateClient = AzureKeyVaultCertificateClient.Create(options);

                return(keyVaultCertificateClient.GetX509Certificate2(options.AzureKeyVaultSecretName));
            });

            return(builder);
        }
        public static IBankIdBuilder UseClientCertificateFromAzureKeyVault(this IBankIdBuilder builder)
        {
            builder.UseClientCertificate(() =>
            {
                var options = builder.AuthenticationBuilder.Services
                              .BuildServiceProvider()
                              .GetService <IOptions <ClientCertificateFromAzureKeyVaultOptions> >();

                using (var keyVaultCertificateClient = AzureKeyVaultCertificateClient.Create(options.Value))
                {
                    if (string.IsNullOrEmpty(options.Value.AzureKeyVaultSecretIdentifier))
                    {
                        throw new ArgumentNullException(nameof(options.Value.AzureKeyVaultSecretIdentifier));
                    }

                    return(keyVaultCertificateClient.GetX509Certificate2Async(options.Value.AzureKeyVaultSecretIdentifier)
                           .ConfigureAwait(false)
                           .GetAwaiter()
                           .GetResult());
                }
            });

            return(builder);
        }