Example #1
0
        protected AzureCredential(IdentityClientOptions options)
        {
            options = options ?? new IdentityClientOptions();

            _client = new IdentityClient(options);

            _refreshBuffer = options.RefreshBuffer;
        }
Example #2
0
        public IdentityClient(IdentityClientOptions options = null)
        {
            _options = options ?? new IdentityClientOptions();

            _pipeline = HttpPipelineBuilder.Build(_options,
                                                  _options.RetryPolicy,
                                                  ClientRequestIdPolicy.Shared,
                                                  BufferResponsePolicy.Shared);
        }
Example #3
0
        public IdentityClient(IdentityClientOptions options = null)
        {
            _options = options ?? new IdentityClientOptions();

            _pipeline = HttpPipeline.Build(_options,
                                           _options.ResponseClassifier,
                                           _options.RetryPolicy,
                                           ClientRequestIdPolicy.Singleton,
                                           BufferResponsePolicy.Singleton);
        }
        /// <summary>
        /// Creates a new InteractiveBrowserCredential with the specifeid options, which will authenticate users with the specified application.
        /// </summary>
        /// <param name="clientId">The client id of the application to which the users will authenticate</param>
        /// TODO: need to link to info on how the application has to be created to authenticate users, for multiple applications
        /// <param name="options">The client options for the newly created DeviceCodeCredential</param>
        public InteractiveBrowserCredential(string clientId, IdentityClientOptions options)
        {
            _clientId = clientId ?? throw new ArgumentNullException(nameof(clientId));

            _options = options ??= new IdentityClientOptions();

            var pipeline = HttpPipelineBuilder.Build(_options);

            _pubApp = PublicClientApplicationBuilder.Create(_clientId).WithHttpClientFactory(new HttpPipelineClientFactory(pipeline)).WithRedirectUri("http://localhost").Build();
        }
Example #5
0
        public EnvironmentCredential(IdentityClientOptions options)
        {
            string tenantId     = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            string clientId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            string clientSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");

            if (tenantId != null && clientId != null && clientSecret != null)
            {
                _credential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
            }
        }
Example #6
0
        /// <summary>
        /// Creates a new DeviceCodeCredential with the specifeid options, which will authenticate users with the specified application.
        /// </summary>
        /// <param name="clientId">The client id of the application to which the users will authenticate</param>
        /// <param name="options">The client options for the newly created DeviceCodeCredential</param>
        /// <param name="deviceCodeCallback">The callback to be executed to display the device code to the user</param>
        public DeviceCodeCredential(string clientId, Func <DeviceCodeInfo, CancellationToken, Task> deviceCodeCallback, IdentityClientOptions options)
        {
            _clientId = clientId ?? throw new ArgumentNullException(nameof(clientId));

            _deviceCodeCallback = deviceCodeCallback ?? throw new ArgumentNullException(nameof(deviceCodeCallback));

            _options = options ?? new IdentityClientOptions();

            _pipeline = HttpPipelineBuilder.Build(_options);

            _pubApp = PublicClientApplicationBuilder.Create(_clientId).WithHttpClientFactory(new HttpPipelineClientFactory(_pipeline)).WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient").Build();
        }
        /// <summary>
        /// Creates an instance of the UsernamePasswordCredential with the details needed to authenticate against Azure Active Directory with a simple username
        /// and password.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password">The user account's user name, UPN.</param>
        /// <param name="clientId">The client (application) ID of an App Registration in the tenant.</param>
        /// <param name="tenantId">The Azure Active Directory tenant (directory) ID or name.</param>
        /// <param name="options">The client options for the newly created UsernamePasswordCredential</param>
        public UsernamePasswordCredential(string username, SecureString password, string clientId, string tenantId, IdentityClientOptions options)
        {
            _username = username ?? throw new ArgumentNullException(nameof(username));

            _password = password ?? throw new ArgumentNullException(nameof(password));

            _options = options ?? new IdentityClientOptions();

            _pipeline = HttpPipelineBuilder.Build(_options, bufferResponse: true);

            _pubApp = PublicClientApplicationBuilder.Create(clientId).WithHttpClientFactory(new HttpPipelineClientFactory(_pipeline)).WithTenantId(tenantId).Build();
        }
Example #8
0
        /// <summary>
        /// Creates a new InteractiveBrowserCredential with the specifeid options, which will authenticate users with the specified application.
        /// </summary>
        /// <param name="clientId">The client id of the application to which the users will authenticate</param>
        /// <param name="tenantId">The tenant id of the application to which users will authenticate.  This can be unspecified for multi-tenanted applications.</param>
        /// TODO: need to link to info on how the application has to be created to authenticate users, for multiple tenant applications
        /// <param name="options">The client options for the newly created DeviceCodeCredential</param>
        public InteractiveBrowserCredential(string clientId, string tenantId = default, IdentityClientOptions options = default)
        {
            _clientId = clientId ?? throw new ArgumentNullException(nameof(clientId));

            _options = options ??= new IdentityClientOptions();

            HttpPipeline pipeline = HttpPipelineBuilder.Build(_options);

            var pubAppBuilder = PublicClientApplicationBuilder.Create(_clientId).WithHttpClientFactory(new HttpPipelineClientFactory(pipeline)).WithRedirectUri("http://localhost");

            if (!string.IsNullOrEmpty(tenantId))
            {
                pubAppBuilder = pubAppBuilder.WithTenantId(tenantId);
            }

            _pubApp = pubAppBuilder.Build();
        }
Example #9
0
        public AadIdentityClient(IdentityClientOptions options = null)
        {
            _options = options ?? new IdentityClientOptions();

            _pipeline = HttpPipelineBuilder.Build(_options, bufferResponse: true);
        }
Example #10
0
        public ClientSecretCredential(string tenantId, string clientId, string clientSecret, IdentityClientOptions options)
        {
            _tenantId     = tenantId;
            _clientId     = clientId;
            _clientSecret = clientSecret;

            _client = (options != null) ? new IdentityClient(options) : IdentityClient.SharedClient;
        }
Example #11
0
        public AadIdentityClient(IdentityClientOptions options = null)
        {
            _options = options ?? new IdentityClientOptions();

            _pipeline = HttpPipelineBuilder.Build(_options);
        }
        public ManagedIdentityCredential(string clientId = null, IdentityClientOptions options = null)
        {
            _clientId = clientId;

            _client = (options != null) ? new IdentityClient(options) : IdentityClient.SharedClient;
        }
Example #13
0
 public ManagedIdentityCredential(string clientId = null, IdentityClientOptions options = null)
     : base(options)
 {
     _clientId = clientId;
 }
Example #14
0
        /// <summary>
        /// Creates an instance of the ClientSecretCredential with the details needed to authenticate against Azure Active Directory with a prefetched authorization code.
        /// </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="clientSecret">A client secret that was generated for the App Registration used to authenticate the client.</param>
        /// <param name="authorizationCode">The authorization code obtained from a call to authorize. The code should be obtained with all required scopes.
        /// See https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow for more information.</param>
        /// <param name="options">Options that allow to configure the management of the requests sent to the Azure Active Directory service.</param>
        public AuthorizationCodeCredential(string tenantId, string clientId, string clientSecret, string authorizationCode, IdentityClientOptions options)
        {
            if (tenantId is null)
            {
                throw new ArgumentNullException(nameof(tenantId));
            }
            if (clientId is null)
            {
                throw new ArgumentNullException(nameof(clientId));
            }
            if (clientSecret is null)
            {
                throw new ArgumentNullException(nameof(clientSecret));
            }

            _authCode = authorizationCode ?? throw new ArgumentNullException(nameof(authorizationCode));

            options ??= new IdentityClientOptions();

            _pipeline = HttpPipelineBuilder.Build(options);

            _confidentialClient = ConfidentialClientApplicationBuilder.Create(clientId).WithHttpClientFactory(new HttpPipelineClientFactory(_pipeline)).WithTenantId(tenantId).WithClientSecret(clientSecret).Build();
        }
Example #15
0
 /// <summary>
 /// Creates an instance of the DefaultAzureCredential class.
 /// </summary>
 public DefaultAzureCredential(IdentityClientOptions options)
     : base(new EnvironmentCredential(options), new ManagedIdentityCredential(options: options), new CredentialNotFoundGuard())
 {
 }
Example #16
0
 public ClientSecretCredential(string tenantId, string clientId, string clientSecret, IdentityClientOptions options)
     : base(options)
 {
     TenantId     = tenantId;
     ClientId     = clientId;
     ClientSecret = clientSecret;
 }
        /// <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, IdentityClientOptions options)
        {
            TenantId = tenantId ?? throw new ArgumentNullException(nameof(tenantId));

            ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));

            ClientCertificate = clientCertificate ?? throw new ArgumentNullException(nameof(clientCertificate));

            _client = (options != null) ? new AadIdentityClient(options) : AadIdentityClient.SharedClient;
        }
Example #18
0
 public SystemCredential(IdentityClientOptions options)
     : base(new EnvironmentCredential(options), new ManagedIdentityCredential(options: options))
 {
 }