コード例 #1
0
        public override async Task <TokenResponse> ExchangeTokenAsync(string userId, string connectionName, string channelId, TokenExchangeRequest exchangeRequest, CancellationToken cancellationToken)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(ExchangeTokenAsync));
            }

            _ = userId ?? throw new ArgumentNullException(nameof(userId));
            _ = connectionName ?? throw new ArgumentNullException(nameof(connectionName));

            _logger.LogInformation($"ExchangeAsyncAsync ConnectionName: {connectionName}");
            var result = await _client.ExchangeAsyncAsync(userId, connectionName, channelId, exchangeRequest, cancellationToken).ConfigureAwait(false);

            if (result is ErrorResponse errorResponse)
            {
                throw new InvalidOperationException($"Unable to exchange token: ({errorResponse?.Error?.Code}) {errorResponse?.Error?.Message}");
            }
            else if (result is TokenResponse tokenResponse)
            {
                return(tokenResponse);
            }
            else
            {
                throw new InvalidOperationException($"ExchangeAsyncAsync returned improper result: {result.GetType()}");
            }
        }
コード例 #2
0
        public async Task ExchangeAsyncWithHttpMessagesAsync_ShouldThrowOnNoLocalBot()
        {
            var client = new OAuthClient(new Uri("http://localhost"), new BotAccessTokenStub("token"));

            ServiceClientTracing.IsEnabled = true;

            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AGENT_OS")) &&
                Environment.GetEnvironmentVariable("AGENT_OS").Equals("Windows_NT"))
            {
                // Automated Windows build exception:
                await client.ExchangeAsyncAsync(
                    "dummyUserId", "dummyConnectionName", "dummyChannelId", new TokenExchangeRequest());

                Assert.True(true, "No exception thrown.");
            }
            else
            {
                // MacLinux build and local build exception:
                await Assert.ThrowsAsync <System.Net.Http.HttpRequestException>(() => client.ExchangeAsyncAsync(
                                                                                    "dummyUserId", "dummyConnectionName", "dummyChannelId", new TokenExchangeRequest()));
            }
        }
コード例 #3
0
 public async Task ExchangeAsyncWithHttpMessagesAsync_ShouldThrowOnNullExchangeRequest()
 {
     var client = new OAuthClient(new Uri("http://localhost"), new BotAccessTokenStub("token"));
     await Assert.ThrowsAsync <ValidationException>(() => client.ExchangeAsyncAsync(
                                                        "dummyUserId", "dummyConnectionName", "dummyChannelId", null));
 }