Skip to content

Commit 47b5ce7

Browse files
committed
* Use OAuth2 for HTTP API access. Thanks @MarcialRosales
1 parent bba3640 commit 47b5ce7

File tree

6 files changed

+16
-22
lines changed

6 files changed

+16
-22
lines changed

projects/Test/OAuth2/OAuth2Options.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public override string ClientId
9696
{
9797
return _mode switch
9898
{
99-
Mode.uaa => "rabbit_client_code",
99+
Mode.uaa => "mgt_api_client",
100100
Mode.keycloak => "mgt_api_client",
101101
_ => throw new InvalidOperationException(),
102102
};
@@ -109,7 +109,7 @@ public override string ClientSecret
109109
{
110110
return _mode switch
111111
{
112-
Mode.uaa => "rabbit_client_code",
112+
Mode.uaa => "mgt_api_client",
113113
Mode.keycloak => "LWOuYqJ8gjKg3D2U8CJZDuID3KiRZVDa",
114114
_ => throw new InvalidOperationException(),
115115
};

projects/Test/OAuth2/TestOAuth2.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public class TestOAuth2 : IAsyncLifetime
5151
private readonly IConnectionFactory _connectionFactory;
5252
private readonly int _tokenExpiresInSeconds;
5353
private readonly OAuth2ClientCredentialsProvider _producerCredentialsProvider;
54-
// TODO rabbitmq-dotnet-client-1639
55-
// private readonly OAuth2ClientCredentialsProvider _httpApiCredentialsProvider;
54+
private readonly OAuth2ClientCredentialsProvider _httpApiCredentialsProvider;
5655
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
5756

5857
private IConnection? _connection;
@@ -68,9 +67,8 @@ public TestOAuth2(ITestOutputHelper testOutputHelper)
6867
var producerOptions = new OAuth2ProducerOptions(mode);
6968
_producerCredentialsProvider = GetCredentialsProvider(producerOptions);
7069

71-
// TODO rabbitmq-dotnet-client-1639
72-
// var httpApiOptions = new OAuth2HttpApiOptions(mode);
73-
// _httpApiCredentialsProvider = GetCredentialsProvider(httpApiOptions);
70+
var httpApiOptions = new OAuth2HttpApiOptions(mode);
71+
_httpApiCredentialsProvider = GetCredentialsProvider(httpApiOptions);
7472

7573
_connectionFactory = new ConnectionFactory
7674
{
@@ -176,10 +174,8 @@ public async void IntegrationTest()
176174
async Task CloseConnection()
177175
{
178176
Assert.NotNull(_connection);
179-
// TODO rabbitmq-dotnet-client-1639
180-
// Credentials httpApiCredentials = await _httpApiCredentialsProvider.GetCredentialsAsync();
181-
// closeConnectionUtil = new Util("mgt_api_client", httpApiCredentials.Password);
182-
closeConnectionUtil = new Util(_testOutputHelper);
177+
Credentials httpApiCredentials = await _httpApiCredentialsProvider.GetCredentialsAsync();
178+
closeConnectionUtil = new Util(_testOutputHelper, "mgt_api_client", httpApiCredentials.Password);
183179
await closeConnectionUtil.CloseConnectionAsync(_connection.ClientProvidedName);
184180
}
185181

@@ -192,12 +188,12 @@ async Task CloseConnection()
192188
{
193189
await closeConnectionTask;
194190
closeConnectionTask = null;
195-
}
196191

197-
if (closeConnectionUtil != null)
198-
{
199-
closeConnectionUtil.Dispose();
200-
closeConnectionUtil = null;
192+
if (closeConnectionUtil != null)
193+
{
194+
closeConnectionUtil.Dispose();
195+
closeConnectionUtil = null;
196+
}
201197
}
202198

203199
_testOutputHelper.WriteLine("{0} [INFO] Resuming ...", DateTime.Now);

projects/Test/OAuth2/keycloak/import/test-realm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@
508508
"credentials" : [ ],
509509
"disableableCredentialTypes" : [ ],
510510
"requiredActions" : [ ],
511-
"realmRoles" : [ "default-roles-test", "rabbitmq-management", "rabbitmq.tag:management" ],
511+
"realmRoles" : [ "default-roles-test", "rabbitmq-management", "rabbitmq.tag:administrator" ],
512512
"notBefore" : 0,
513513
"groups" : [ ]
514514
}, {

projects/Test/OAuth2/keycloak/rabbitmq.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
log.console = true
22
log.console.level = debug
33

4-
auth_backends.1 = internal
5-
auth_backends.2 = oauth2
4+
auth_backends.1 = oauth2
65

76
auth_oauth2.resource_server_id = rabbitmq
87
auth_oauth2.preferred_username_claims.1 = username

projects/Test/OAuth2/uaa/rabbitmq.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
log.console = true
22
log.console.level = debug
33

4-
auth_backends.1 = internal
5-
auth_backends.2 = oauth2
4+
auth_backends.1 = oauth2
65

76
management.oauth_enabled = true
87
management.oauth_client_id = rabbit_client_code

projects/Test/OAuth2/uaa/uaa.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ oauth:
125125
id: mgt_api_client
126126
secret: mgt_api_client
127127
authorized-grant-types: client_credentials
128-
authorities: rabbitmq.tag:monitoring
128+
authorities: rabbitmq.tag:administrator
129129
rabbit_client_code:
130130
id: rabbit_client_code
131131
secret: rabbit_client_code

0 commit comments

Comments
 (0)