Skip to content

Commit d6975b6

Browse files
committed
* Remove the ability to set http client handler on OAuth2Client
* Only warn when a connection can't be deleted * Make `RefreshToken` a nullable string
1 parent c44a2e6 commit d6975b6

File tree

6 files changed

+23
-24
lines changed

6 files changed

+23
-24
lines changed

projects/RabbitMQ.Client.OAuth2/OAuth2Client.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class OAuth2ClientBuilder
4747
private readonly Uri _tokenEndpoint;
4848
private string? _scope;
4949
private IDictionary<string, string>? _additionalRequestParameters;
50-
private HttpClientHandler? _httpClientHandler;
5150

5251
public OAuth2ClientBuilder(string clientId, string clientSecret, Uri tokenEndpoint)
5352
{
@@ -62,12 +61,6 @@ public OAuth2ClientBuilder SetScope(string scope)
6261
return this;
6362
}
6463

65-
public OAuth2ClientBuilder SetHttpClientHandler(HttpClientHandler handler)
66-
{
67-
_httpClientHandler = handler ?? throw new ArgumentNullException(nameof(handler));
68-
return this;
69-
}
70-
7164
public OAuth2ClientBuilder AddRequestParameter(string param, string paramValue)
7265
{
7366
if (param == null)
@@ -92,7 +85,7 @@ public OAuth2ClientBuilder AddRequestParameter(string param, string paramValue)
9285
public IOAuth2Client Build()
9386
{
9487
return new OAuth2Client(_clientId, _clientSecret, _tokenEndpoint,
95-
_scope, _additionalRequestParameters, _httpClientHandler);
88+
_scope, _additionalRequestParameters);
9689
}
9790
}
9891

@@ -123,17 +116,15 @@ internal class OAuth2Client : IOAuth2Client, IDisposable
123116

124117
public OAuth2Client(string clientId, string clientSecret, Uri tokenEndpoint,
125118
string? scope,
126-
IDictionary<string, string>? additionalRequestParameters,
127-
HttpClientHandler? httpClientHandler)
119+
IDictionary<string, string>? additionalRequestParameters)
128120
{
129121
_clientId = clientId;
130122
_clientSecret = clientSecret;
131123
_scope = scope;
132124
_additionalRequestParameters = additionalRequestParameters == null ? EMPTY : additionalRequestParameters;
133125
_tokenEndpoint = tokenEndpoint;
134126

135-
_httpClient = httpClientHandler == null ? new HttpClient() :
136-
new HttpClient(httpClientHandler);
127+
_httpClient = new HttpClient();
137128
_httpClient.DefaultRequestHeaders.Accept.Clear();
138129
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
139130
}
@@ -219,7 +210,7 @@ private Dictionary<string, string> BuildRequestParameters()
219210

220211
private Dictionary<string, string> BuildRefreshParameters(IToken token)
221212
{
222-
var dict = BuildRequestParameters();
213+
Dictionary<string, string> dict = BuildRequestParameters();
223214
dict.Remove(GRANT_TYPE);
224215
dict.Add(GRANT_TYPE, REFRESH_TOKEN);
225216

@@ -228,7 +219,10 @@ private Dictionary<string, string> BuildRefreshParameters(IToken token)
228219
dict.Add(SCOPE, _scope);
229220
}
230221

231-
dict.Add(REFRESH_TOKEN, token.RefreshToken);
222+
if (token.RefreshToken != null)
223+
{
224+
dict.Add(REFRESH_TOKEN, token.RefreshToken);
225+
}
232226

233227
return dict;
234228
}
@@ -263,7 +257,7 @@ public string AccessToken
263257
}
264258

265259
[JsonPropertyName("refresh_token")]
266-
public string RefreshToken
260+
public string? RefreshToken
267261
{
268262
get; set;
269263
}

projects/RabbitMQ.Client.OAuth2/PublicAPI.Shipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ RabbitMQ.Client.OAuth2.OAuth2ClientBuilder
99
RabbitMQ.Client.OAuth2.OAuth2ClientBuilder.AddRequestParameter(string param, string paramValue) -> RabbitMQ.Client.OAuth2.OAuth2ClientBuilder
1010
RabbitMQ.Client.OAuth2.OAuth2ClientBuilder.Build() -> RabbitMQ.Client.OAuth2.IOAuth2Client
1111
RabbitMQ.Client.OAuth2.OAuth2ClientBuilder.OAuth2ClientBuilder(string clientId, string clientSecret, System.Uri tokenEndpoint) -> void
12-
RabbitMQ.Client.OAuth2.OAuth2ClientBuilder.SetHttpClientHandler(System.Net.Http.HttpClientHandler handler) -> RabbitMQ.Client.OAuth2.OAuth2ClientBuilder
1312
RabbitMQ.Client.OAuth2.OAuth2ClientBuilder.SetScope(string scope) -> RabbitMQ.Client.OAuth2.OAuth2ClientBuilder
1413
RabbitMQ.Client.OAuth2.OAuth2ClientCredentialsProvider
1514
RabbitMQ.Client.OAuth2.OAuth2ClientCredentialsProvider.Name.get -> string

projects/RabbitMQ.Client.OAuth2/Token.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace RabbitMQ.Client.OAuth2
3636
public interface IToken
3737
{
3838
string AccessToken { get; }
39-
string RefreshToken { get; }
39+
string? RefreshToken { get; }
4040
TimeSpan ExpiresIn { get; }
4141
bool HasExpired { get; }
4242
}
@@ -60,7 +60,7 @@ public string AccessToken
6060
}
6161
}
6262

63-
public string RefreshToken
63+
public string? RefreshToken
6464
{
6565
get
6666
{

projects/Test/Common/TestConnectionRecoveryBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ namespace Test
4242
{
4343
public class TestConnectionRecoveryBase : IntegrationFixture, IDisposable
4444
{
45-
private readonly Util _util = new Util();
45+
private readonly Util _util;
4646
protected readonly byte[] _messageBody;
4747
protected const ushort TotalMessageCount = 16384;
4848
protected const ushort CloseAtCount = 16;
4949

5050
public TestConnectionRecoveryBase(ITestOutputHelper output)
5151
: base(output)
5252
{
53+
_util = new Util(output);
5354
_messageBody = GetRandomBody(4096);
5455
}
5556

projects/Test/Common/Util.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
using System.Linq;
55
using System.Threading.Tasks;
66
using EasyNetQ.Management.Client;
7+
using Xunit.Abstractions;
78

89
namespace Test
910
{
1011
public class Util : IDisposable
1112
{
13+
private readonly ITestOutputHelper _output;
1214
private readonly ManagementClient _managementClient;
1315
private static readonly bool s_isWindows = false;
1416

@@ -17,12 +19,14 @@ static Util()
1719
s_isWindows = InitIsWindows();
1820
}
1921

20-
public Util() : this("guest", "guest")
22+
public Util(ITestOutputHelper output) : this(output, "guest", "guest")
2123
{
2224
}
2325

24-
public Util(string managementUsername, string managementPassword)
26+
public Util(ITestOutputHelper output, string managementUsername, string managementPassword)
2527
{
28+
_output = output;
29+
2630
if (string.IsNullOrEmpty(managementUsername))
2731
{
2832
managementUsername = "guest";
@@ -37,7 +41,7 @@ public Util(string managementUsername, string managementPassword)
3741
_managementClient = new ManagementClient(managementUri, managementUsername, managementPassword);
3842
}
3943

40-
public static string Now => DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture);
44+
public static string Now => DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture);
4145

4246
public static bool IsWindows => s_isWindows;
4347

@@ -90,7 +94,8 @@ public async Task CloseConnectionAsync(string connectionClientProvidedName)
9094

9195
if (connectionToClose == null)
9296
{
93-
throw new InvalidOperationException($"Could not delete connection: '{connectionClientProvidedName}'");
97+
_output.WriteLine("{0} [WARNING] could not find/delete connection: '{1}'",
98+
Now, connectionClientProvidedName);
9499
}
95100
}
96101

projects/Test/OAuth2/TestOAuth2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async Task CloseConnection()
179179
// TODO rabbitmq-dotnet-client-1639
180180
// Credentials httpApiCredentials = await _httpApiCredentialsProvider.GetCredentialsAsync();
181181
// closeConnectionUtil = new Util("mgt_api_client", httpApiCredentials.Password);
182-
closeConnectionUtil = new Util();
182+
closeConnectionUtil = new Util(_testOutputHelper);
183183
await closeConnectionUtil.CloseConnectionAsync(_connection.ClientProvidedName);
184184
}
185185

0 commit comments

Comments
 (0)