示例#1
0
        public static AzureKeyVaultCertificateClient Create(ClientCertificateFromAzureKeyVaultOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.AzureKeyVaultUri))
            {
                throw new ArgumentException("AzureKeyVaultUri is required");
            }

            if (!options.UseManagedIdentity)
            {
                if (string.IsNullOrWhiteSpace(options.AzureAdTenantId))
                {
                    throw new ArgumentException("AzureAdTenantId is required when not using ManagedIdentity");
                }

                if (string.IsNullOrWhiteSpace(options.AzureAdClientId))
                {
                    throw new ArgumentException("AzureAdClientId is required when not using ManagedIdentity");
                }

                if (string.IsNullOrWhiteSpace(options.AzureAdClientSecret))
                {
                    throw new ArgumentException("AzureAdClientSecret is required when not using ManagedIdentity");
                }
            }

            var tokenCredentials = GetTokenCredential(options);
            var secretClient     = new SecretClient(new Uri(options.AzureKeyVaultUri), tokenCredentials);

            return(new AzureKeyVaultCertificateClient(secretClient));
        }
        public static AzureKeyVaultCertificateClient Create(ClientCertificateFromAzureKeyVaultOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.AzureKeyVaultUri))
            {
                throw new ArgumentException("AzureKeyVaultUri is required");
            }

            var tokenCredentials = GetTokenCredential(options);
            var secretClient     = new SecretClient(new Uri(options.AzureKeyVaultUri), tokenCredentials);

            return(new AzureKeyVaultCertificateClient(secretClient));
        }
示例#3
0
        private static TokenCredential GetTokenCredential(ClientCertificateFromAzureKeyVaultOptions options)
        {
            if (!options.UseManagedIdentity)
            {
                return(new ClientSecretCredential(
                           options.AzureAdTenantId,
                           options.AzureAdClientId,
                           options.AzureAdClientSecret
                           ));
            }

            return(new ManagedIdentityCredential());
        }
        private static TokenCredential GetTokenCredential(ClientCertificateFromAzureKeyVaultOptions options)
        {
            if (!string.IsNullOrEmpty(options.AzureAdTenantId) &&
                !string.IsNullOrEmpty(options.AzureAdClientId) &&
                !string.IsNullOrEmpty(options.AzureAdClientSecret))
            {
                return(new ClientSecretCredential(
                           options.AzureAdTenantId,
                           options.AzureAdClientId,
                           options.AzureAdClientSecret
                           ));
            }

            if (!string.IsNullOrEmpty(options.AzureManagedIdentityClientId))
            {
                return(new DefaultAzureCredential(new DefaultAzureCredentialOptions()
                {
                    ManagedIdentityClientId = options.AzureManagedIdentityClientId
                }));
            }

            return(new DefaultAzureCredential());
        }