From dd17ea88b62b175453826eb6aa20474dc0ea8065 Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Mon, 5 Feb 2024 15:16:02 -0500 Subject: [PATCH] oauth2_client: cosmetics (cherry picked from commit 49f7aa30b3860767f664a136ba3337f147131d38) --- deps/oauth2_client/src/oauth2_client.erl | 49 ++++++++++++--------- deps/oauth2_client/test/oauth_http_mock.erl | 7 +++ deps/oauth2_client/test/system_SUITE.erl | 3 +- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/deps/oauth2_client/src/oauth2_client.erl b/deps/oauth2_client/src/oauth2_client.erl index 3ad3973126..ac8cebf32b 100644 --- a/deps/oauth2_client/src/oauth2_client.erl +++ b/deps/oauth2_client/src/oauth2_client.erl @@ -1,3 +1,9 @@ +%% This Source Code Form is subject to the terms of the Mozilla Public +%% License, v. 2.0. If a copy of the MPL was not distributed with this +%% file, You can obtain one at https://mozilla.org/MPL/2.0/. +%% +%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. +%% -module(oauth2_client). -export([get_access_token/2, refresh_access_token/2, @@ -261,12 +267,13 @@ lookup_oauth_provider_from_keyconfig() -> TokenEndpoint = application:get_env(rabbitmq_auth_backend_oauth2, token_endpoint, undefined), Map = maps:from_list(application:get_env(rabbitmq_auth_backend_oauth2, key_config, [])), #oauth_provider{ - issuer=Issuer, - jwks_uri=maps:get(jwks_url, Map, undefined), %% jwks_url not uri . _url is the legacy name - token_endpoint=TokenEndpoint, - ssl_options=extract_ssl_options_as_list(Map) + issuer = Issuer, + jwks_uri = maps:get(jwks_url, Map, undefined), %% jwks_url not uri . _url is the legacy name + token_endpoint = TokenEndpoint, + ssl_options = extract_ssl_options_as_list(Map) }. +-spec extract_ssl_options_as_list(#{atom() => any()}) -> proplists:proplist(). extract_ssl_options_as_list(Map) -> Verify = case maps:get(cacertfile, Map, undefined) of undefined -> verify_none; @@ -360,36 +367,36 @@ decode_body(MimeType, Body) -> end. -map_to_successful_access_token_response(Json) -> +map_to_successful_access_token_response(Map) -> #successful_access_token_response{ - access_token=maps:get(?RESPONSE_ACCESS_TOKEN, Json), - token_type=maps:get(?RESPONSE_TOKEN_TYPE, Json, undefined), - refresh_token=maps:get(?RESPONSE_REFRESH_TOKEN, Json, undefined), - expires_in=maps:get(?RESPONSE_EXPIRES_IN, Json, undefined) + access_token = maps:get(?RESPONSE_ACCESS_TOKEN, Map), + token_type = maps:get(?RESPONSE_TOKEN_TYPE, Map, undefined), + refresh_token = maps:get(?RESPONSE_REFRESH_TOKEN, Map, undefined), + expires_in = maps:get(?RESPONSE_EXPIRES_IN, Map, undefined) }. -map_to_unsuccessful_access_token_response(Json) -> +map_to_unsuccessful_access_token_response(Map) -> #unsuccessful_access_token_response{ - error=maps:get(?RESPONSE_ERROR, Json), - error_description=maps:get(?RESPONSE_ERROR_DESCRIPTION, Json, undefined) + error = maps:get(?RESPONSE_ERROR, Map), + error_description = maps:get(?RESPONSE_ERROR_DESCRIPTION, Map, undefined) }. map_to_oauth_provider(Map) when is_map(Map) -> #oauth_provider{ - issuer=maps:get(?RESPONSE_ISSUER, Map), - token_endpoint=maps:get(?RESPONSE_TOKEN_ENDPOINT, Map, undefined), - authorization_endpoint=maps:get(?RESPONSE_AUTHORIZATION_ENDPOINT, Map, undefined), - jwks_uri=maps:get(?RESPONSE_JWKS_URI, Map, undefined) + issuer = maps:get(?RESPONSE_ISSUER, Map), + token_endpoint = maps:get(?RESPONSE_TOKEN_ENDPOINT, Map, undefined), + authorization_endpoint = maps:get(?RESPONSE_AUTHORIZATION_ENDPOINT, Map, undefined), + jwks_uri = maps:get(?RESPONSE_JWKS_URI, Map, undefined) }; map_to_oauth_provider(PropList) when is_list(PropList) -> #oauth_provider{ - issuer=proplists:get_value(issuer, PropList), - token_endpoint=proplists:get_value(token_endpoint, PropList), - authorization_endpoint=proplists:get_value(authorization_endpoint, PropList, undefined), - jwks_uri=proplists:get_value(jwks_uri, PropList, undefined), - ssl_options=map_ssl_options(proplists:get_value(https, PropList, undefined)) + issuer = proplists:get_value(issuer, PropList), + token_endpoint = proplists:get_value(token_endpoint, PropList), + authorization_endpoint = proplists:get_value(authorization_endpoint, PropList, undefined), + jwks_uri = proplists:get_value(jwks_uri, PropList, undefined), + ssl_options = map_ssl_options(proplists:get_value(https, PropList, undefined)) }. map_ssl_options(undefined) -> diff --git a/deps/oauth2_client/test/oauth_http_mock.erl b/deps/oauth2_client/test/oauth_http_mock.erl index 2647515dc3..7b57a6bb73 100644 --- a/deps/oauth2_client/test/oauth_http_mock.erl +++ b/deps/oauth2_client/test/oauth_http_mock.erl @@ -1,3 +1,10 @@ +%% This Source Code Form is subject to the terms of the Mozilla Public +%% License, v. 2.0. If a copy of the MPL was not distributed with this +%% file, You can obtain one at https://mozilla.org/MPL/2.0/. +%% +%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. +%% + -module(oauth_http_mock). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). diff --git a/deps/oauth2_client/test/system_SUITE.erl b/deps/oauth2_client/test/system_SUITE.erl index fd2b739822..59523ed584 100644 --- a/deps/oauth2_client/test/system_SUITE.erl +++ b/deps/oauth2_client/test/system_SUITE.erl @@ -2,7 +2,8 @@ %% License, v. 2.0. If a copy of the MPL was not distributed with this %% file, You can obtain one at https://mozilla.org/MPL/2.0/. %% -%% Copyright (c) 2017-2023 VMware, Inc. or its affiliates. All rights reserved. +%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. +%% -module(system_SUITE).