Exemplo n.º 1
0
        internal EnvironmentCredential(CredentialPipeline pipeline, TokenCredentialOptions options = null)
        {
            _pipeline = pipeline;
            _options  = options ?? new TokenCredentialOptions();

            string tenantId                   = EnvironmentVariables.TenantId;
            string clientId                   = EnvironmentVariables.ClientId;
            string clientSecret               = EnvironmentVariables.ClientSecret;
            string clientCertificatePath      = EnvironmentVariables.ClientCertificatePath;
            string clientSendCertificateChain = EnvironmentVariables.ClientSendCertificateChain;
            string username                   = EnvironmentVariables.Username;
            string password                   = EnvironmentVariables.Password;

            if (!string.IsNullOrEmpty(tenantId) && !string.IsNullOrEmpty(clientId))
            {
                if (!string.IsNullOrEmpty(clientSecret))
                {
                    Credential = new ClientSecretCredential(tenantId, clientId, clientSecret, _options, _pipeline, null);
                }
                else if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
                {
                    Credential = new UsernamePasswordCredential(username, password, tenantId, clientId, _options, _pipeline, null);
                }
                else if (!string.IsNullOrEmpty(clientCertificatePath))
                {
                    bool sendCertificateChain = !string.IsNullOrEmpty(clientSendCertificateChain) &&
                                                (clientSendCertificateChain == "1" || clientSendCertificateChain == "true");

                    ClientCertificateCredentialOptions clientCertificateCredentialOptions = new ClientCertificateCredentialOptions
                    {
                        AuthorityHost        = _options.AuthorityHost,
                        IsLoggingPIIEnabled  = _options.IsLoggingPIIEnabled,
                        Transport            = _options.Transport,
                        SendCertificateChain = sendCertificateChain
                    };
                    Credential = new ClientCertificateCredential(tenantId, clientId, clientCertificatePath, clientCertificateCredentialOptions, _pipeline, null);
                }
            }
        }
        /// <summary>
        /// Creates an instance of the ClientCertificateCredential with the details needed to authenticate against Azure Active Directory with the specified certificate.
        /// </summary>
        /// <param name="tenantId">The Azure Active Directory tenant (directory) Id of the service principal.</param>
        /// <param name="clientId">The client (application) ID of the service principal</param>
        /// <param name="clientCertificatePath">The path to a file which contains both the client certificate and private key.</param>
        /// <param name="options">Options that allow to configure the management of the requests sent to the Azure Active Directory service.</param>
        internal ClientCertificateCredential(string tenantId, string clientId, string clientCertificatePath, ClientCertificateCredentialOptions options)
            : this(tenantId, clientId, clientCertificatePath, options, null, null)

        {
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates an instance of the ClientCertificateCredential with the details needed to authenticate against Azure Active Directory with the specified certificate.
 /// </summary>
 /// <param name="tenantId">The Azure Active Directory tenant (directory) Id of the service principal.</param>
 /// <param name="clientId">The client (application) ID of the service principal</param>
 /// <param name="clientCertificate">The authentication X509 Certificate of the service principal</param>
 /// <param name="options">Options that allow to configure the management of the requests sent to the Azure Active Directory service.</param>
 public ClientCertificateCredential(string tenantId, string clientId, X509Certificate2 clientCertificate, ClientCertificateCredentialOptions options)
     : this(tenantId, clientId, clientCertificate, options, null, null)
 {
 }