Exemplo n.º 1
0
        public void ConnectorClient_CustomHttpClient_ContainsAcceptAll()
        {
            var customHttpClient = new HttpClient();

            ConnectorClient.AddDefaultRequestHeaders(customHttpClient);

            Assert.Contains("*/*", customHttpClient.DefaultRequestHeaders.Accept.ToString());
        }
Exemplo n.º 2
0
 public BotFrameworkHttpClient(
     HttpClient httpClient,
     ICredentialProvider credentialProvider,
     IChannelProvider channelProvider = null,
     ILogger logger = null)
 {
     _httpClient         = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
     _credentialProvider = credentialProvider ?? throw new ArgumentNullException(nameof(credentialProvider));
     _channelProvider    = channelProvider;
     _logger             = logger ?? NullLogger.Instance;
     ConnectorClient.AddDefaultRequestHeaders(_httpClient);
 }
Exemplo n.º 3
0
 public BotFrameworkClientImpl(
     ServiceClientCredentialsFactory credentialsFactory,
     IHttpClientFactory httpClientFactory,
     string loginEndpoint,
     ILogger logger)
 {
     _credentialsFactory = credentialsFactory;
     _httpClient         = httpClientFactory?.CreateClient() ?? new HttpClient();
     _loginEndpoint      = loginEndpoint;
     _logger             = logger ?? NullLogger.Instance;
     ConnectorClient.AddDefaultRequestHeaders(_httpClient);
 }
Exemplo n.º 4
0
        public void ConnectorClient_CustomHttpClient_UserAgentContainsAspNetVersion()
        {
            var customHttpClient = new HttpClient();

            ConnectorClient.AddDefaultRequestHeaders(customHttpClient);

            // The AspNetVersion string is modified, to be used in a ProductInfoHeaderValue.
            // This test replaces the same characters as what are required to construct a valid ProductInfoHeaderValue
            var aspNetVersion = ConnectorClient.GetASPNetVersion().Replace(",", string.Empty).Replace(" ", string.Empty).Replace("=", string.Empty);

            Assert.Contains(aspNetVersion, customHttpClient.DefaultRequestHeaders.UserAgent.ToString().Replace("/", string.Empty));
        }
        public override async Task <IConnectorClient> CreateAsync(string serviceUrl, string audience, CancellationToken cancellationToken)
        {
            // Use the credentials factory to create credentails specific to this particular cloud environment.
            var credentials = await _credentialFactory.CreateCredentialsAsync(_appId, audience ?? _toChannelFromBotOAuthScope, _loginEndpoint, _validateAuthority, cancellationToken).ConfigureAwait(false);

            // A new connector client for making calls against this serviceUrl using credentials derived from the current appId and the specified audience.
#pragma warning disable CA2000 // Dispose objects before losing scope
            var httpClient = _httpClientFactory?.CreateClient() ?? new HttpClient();
            ConnectorClient.AddDefaultRequestHeaders(httpClient);
            return(new ConnectorClient(new Uri(serviceUrl), credentials, httpClient, true));

#pragma warning restore CA2000 // Dispose objects before losing scope
        }
 public UserTokenClientImpl(
     string appId,
     ServiceClientCredentials credentials,
     string oauthEndpoint,
     HttpClient httpClient,
     ILogger logger)
 {
     _appId      = appId;
     _httpClient = httpClient ?? new HttpClient();
     ConnectorClient.AddDefaultRequestHeaders(_httpClient);
     _client = new OAuthClient(credentials, _httpClient, true)
     {
         BaseUri = new Uri(oauthEndpoint)
     };
     _logger = logger ?? NullLogger.Instance;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BotFrameworkSkillHostAdapter"/> class,
        /// using a credential provider.
        /// </summary>
        /// <param name="adapter">adapter that this skillAdapter is bound to.</param>
        /// <param name="credentialProvider">The credential provider.</param>
        /// <param name="authConfig">The authentication configuration.</param>
        /// <param name="channelProvider">The channel provider.</param>
        /// <param name="connectorClientRetryPolicy">Retry policy for retrying HTTP operations.</param>
        /// <param name="customHttpClient">The HTTP client.</param>
        /// <param name="logger">The ILogger implementation this adapter should use.</param>
        /// <exception cref="ArgumentNullException">throw ArgumentNullException.</exception>
        /// <remarks>Use a <see cref="MiddlewareSet"/> object to add multiple middleware
        /// components in the constructor. Use the Use(<see cref="IMiddleware"/>) method to
        /// add additional middleware to the adapter after construction.
        /// </remarks>
        public BotFrameworkSkillHostAdapter(
            BotAdapter adapter,
            ICredentialProvider credentialProvider,
            AuthenticationConfiguration authConfig,
            IChannelProvider channelProvider       = null,
            RetryPolicy connectorClientRetryPolicy = null,
            HttpClient customHttpClient            = null,
            ILogger logger = null)
            : base(adapter, logger)
        {
            _credentialProvider         = credentialProvider ?? throw new ArgumentNullException(nameof(credentialProvider));
            _channelProvider            = channelProvider;
            _httpClient                 = customHttpClient ?? _defaultHttpClient;
            _connectorClientRetryPolicy = connectorClientRetryPolicy;
            _logger            = logger ?? NullLogger.Instance;
            _authConfiguration = authConfig ?? throw new ArgumentNullException(nameof(authConfig));

            // DefaultRequestHeaders are not thread safe so set them up here because this adapter should be a singleton.
            ConnectorClient.AddDefaultRequestHeaders(_httpClient);
        }