Skip to content

Commit f6dd1e0

Browse files
WIP More refactoring
split rabbit_oauth2_config into - rabbit_oauth2_resource_server - rabbit_oauth2_oauth_provider and their respective test modules Signing keys is an oauth provider concern hence it stays with the oauth_provider module.
1 parent 94d841c commit f6dd1e0

File tree

10 files changed

+1628
-1422
lines changed

10 files changed

+1628
-1422
lines changed

deps/rabbitmq_auth_backend_oauth2/BUILD.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ rabbitmq_integration_suite(
113113
)
114114

115115
rabbitmq_integration_suite(
116-
name = "rabbit_oauth2_config_SUITE",
116+
name = "rabbit_oauth2_oauth_provider_SUITE",
117117
additional_beam = [
118118
"test/oauth2_http_mock.beam",
119119
],
@@ -122,6 +122,10 @@ rabbitmq_integration_suite(
122122
],
123123
)
124124

125+
rabbitmq_integration_suite(
126+
name = "rabbit_oauth2_resource_server_SUITE"
127+
)
128+
125129
rabbitmq_integration_suite(
126130
name = "jwks_SUITE",
127131
additional_beam = [

deps/rabbitmq_auth_backend_oauth2/app.bzl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def all_beam_files(name = "all_beam_files"):
1313
"src/Elixir.RabbitMQ.CLI.Ctl.Commands.AddUaaKeyCommand.erl",
1414
"src/rabbit_auth_backend_oauth2.erl",
1515
"src/rabbit_auth_backend_oauth2_app.erl",
16-
"src/rabbit_oauth2_config.erl",
16+
"src/rabbit_oauth2_oauth_provider.erl",
17+
"src/rabbit_oauth2_resource_server.erl",
1718
"src/rabbit_oauth2_schema.erl",
1819
"src/rabbit_oauth2_scope.erl",
1920
"src/uaa_jwks.erl",
@@ -48,7 +49,8 @@ def all_test_beam_files(name = "all_test_beam_files"):
4849
"src/Elixir.RabbitMQ.CLI.Ctl.Commands.AddUaaKeyCommand.erl",
4950
"src/rabbit_auth_backend_oauth2.erl",
5051
"src/rabbit_auth_backend_oauth2_app.erl",
51-
"src/rabbit_oauth2_config.erl",
52+
"src/rabbit_oauth2_resource_server.erl",
53+
"src/rabbit_oauth2_oauth_provider.erl",
5254
"src/rabbit_oauth2_schema.erl",
5355
"src/rabbit_oauth2_scope.erl",
5456
"src/uaa_jwks.erl",
@@ -85,6 +87,7 @@ def all_srcs(name = "all_srcs"):
8587
)
8688
filegroup(
8789
name = "public_hdrs",
90+
srcs = ["include/oauth2.hrl"],
8891
)
8992

9093
filegroup(
@@ -94,7 +97,8 @@ def all_srcs(name = "all_srcs"):
9497
"src/Elixir.RabbitMQ.CLI.Ctl.Commands.AddUaaKeyCommand.erl",
9598
"src/rabbit_auth_backend_oauth2.erl",
9699
"src/rabbit_auth_backend_oauth2_app.erl",
97-
"src/rabbit_oauth2_config.erl",
100+
"src/rabbit_oauth2_oauth_provider.erl",
101+
"src/rabbit_oauth2_resource_server.erl",
98102
"src/rabbit_oauth2_schema.erl",
99103
"src/rabbit_oauth2_scope.erl",
100104
"src/uaa_jwks.erl",
@@ -236,10 +240,19 @@ def test_suite_beam_files(name = "test_suite_beam_files"):
236240
erlc_opts = "//:test_erlc_opts",
237241
)
238242
erlang_bytecode(
239-
name = "rabbit_oauth2_config_SUITE_beam_files",
243+
name = "rabbit_oauth2_oauth_provider_SUITE_beam_files",
240244
testonly = True,
241-
srcs = ["test/rabbit_oauth2_config_SUITE.erl"],
242-
outs = ["test/rabbit_oauth2_config_SUITE.beam"],
245+
srcs = ["test/rabbit_oauth2_oauth_provider_SUITE.erl"],
246+
outs = ["test/rabbit_oauth2_oauth_provider_SUITE.beam"],
247+
app_name = "rabbitmq_auth_backend_oauth2",
248+
erlc_opts = "//:test_erlc_opts",
249+
deps = ["//deps/oauth2_client:erlang_app"],
250+
)
251+
erlang_bytecode(
252+
name = "rabbit_oauth2_resource_server_SUITE_beam_files",
253+
testonly = True,
254+
srcs = ["test/rabbit_oauth2_resource_server_SUITE.erl"],
255+
outs = ["test/rabbit_oauth2_resource_server_SUITE.beam"],
243256
app_name = "rabbitmq_auth_backend_oauth2",
244257
erlc_opts = "//:test_erlc_opts",
245258
deps = ["//deps/oauth2_client:erlang_app"],
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2020-2023 VMware, Inc. or its affiliates. All rights reserved.
6+
%%
7+
8+
9+
-include_lib("oauth2_client/include/oauth2_client.hrl").
10+
11+
-define(DEFAULT_PREFERRED_USERNAME_CLAIMS, [<<"sub">>, <<"client_id">>]).
12+
13+
-define(TOP_RESOURCE_SERVER_ID, application:get_env(?APP, resource_server_id)).
14+
%% scope aliases map "role names" to a set of scopes
15+
16+
-record(internal_oauth_provider, {
17+
id :: oauth_provider_id(),
18+
default_key :: binary() | undefined,
19+
algorithms :: list() | undefined
20+
}).
21+
-type internal_oauth_provider() :: #internal_oauth_provider{}.
22+
23+
-record(resource_server, {
24+
id :: resource_server_id(),
25+
resource_server_type :: binary(),
26+
verify_aud :: boolean(),
27+
scope_prefix :: binary(),
28+
additional_scopes_key :: binary(),
29+
preferred_username_claims :: list(),
30+
scope_aliases :: undefined | map(),
31+
oauth_provider_id :: oauth_provider_id()
32+
}).
33+
34+
-type resource_server() :: #resource_server{}.
35+
-type resource_server_id() :: binary() | list().

0 commit comments

Comments
 (0)