From 37fd556c039ed7c2538232c630dee061a67d6a12 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Mon, 7 Dec 2020 12:45:34 -0800 Subject: [PATCH 1/4] Add patch for client credential support. --- ...-for-oauth2-using-client-credentials.patch | 131 ++++++++++++++++++ SPECS/cpprest/cpprest.spec | 8 +- 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 SPECS/cpprest/cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch diff --git a/SPECS/cpprest/cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch b/SPECS/cpprest/cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch new file mode 100644 index 00000000000..113f14c2cbe --- /dev/null +++ b/SPECS/cpprest/cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch @@ -0,0 +1,131 @@ +From 708a5df2bb328705622c42f84b4167ea2c7c98c9 Mon Sep 17 00:00:00 2001 +From: Ivan Cherniukh +Date: Wed, 9 Sep 2020 09:09:04 -0700 +Subject: [PATCH] Add support for oauth2 using only client credentials + +--- + .../cpprest/details/http_constants.dat | 1 + + Release/include/cpprest/oauth2.h | 15 ++++ + .../functional/http/client/oauth2_tests.cpp | 68 +++++++++++++++++++ + 3 files changed, 84 insertions(+) + +diff --git a/Release/include/cpprest/details/http_constants.dat b/Release/include/cpprest/details/http_constants.dat +index c3b1a53c..3deb24a1 100644 +--- a/Release/include/cpprest/details/http_constants.dat ++++ b/Release/include/cpprest/details/http_constants.dat +@@ -190,6 +190,7 @@ DAT(expires_in, "expires_in") + DAT(grant_type, "grant_type") + DAT(redirect_uri, "redirect_uri") + DAT(refresh_token, "refresh_token") ++DAT(client_credentials, "client_credentials") + DAT(response_type, "response_type") + DAT(scope, "scope") + DAT(state, "state") +diff --git a/Release/include/cpprest/oauth2.h b/Release/include/cpprest/oauth2.h +index 693ebbe3..68a7c7b9 100644 +--- a/Release/include/cpprest/oauth2.h ++++ b/Release/include/cpprest/oauth2.h +@@ -284,6 +284,21 @@ public: + return _request_token(ub); + } + ++ /// ++ /// Fetches an access token from the token endpoint using client credentials grant type. ++ /// The task creates an HTTP request to the token_endpoint() using ++ /// client authentication as the authorization grant. ++ /// See: http://tools.ietf.org/html/rfc6749#section-4.4 ++ /// ++ /// Task that fetches token(s) using client credentials. ++ pplx::task token_from_client_credentials() ++ { ++ uri_builder ub; ++ ub.append_query( ++ details::oauth2_strings::grant_type, details::oauth2_strings::client_credentials, false); ++ return _request_token(ub); ++ } ++ + /// + /// Returns enabled state of the configuration. + /// The oauth2_handler will perform OAuth 2.0 authentication only if +diff --git a/Release/tests/functional/http/client/oauth2_tests.cpp b/Release/tests/functional/http/client/oauth2_tests.cpp +index e1f54085..08bb12a6 100644 +--- a/Release/tests/functional/http/client/oauth2_tests.cpp ++++ b/Release/tests/functional/http/client/oauth2_tests.cpp +@@ -291,6 +291,74 @@ SUITE(oauth2_tests) + VERIFY_ARE_EQUAL(U("done"), m_oauth2_config.token().access_token()); + } + ++ TEST_FIXTURE(oauth2_test_setup, oauth2_token_from_client_credentials) ++ { ++ VERIFY_IS_FALSE(m_oauth2_config.is_enabled()); ++ ++ m_oauth2_config.set_user_agent(U("test_user_agent")); ++ ++ // Fetch using HTTP Basic authentication. ++ { ++ m_scoped.server()->next_request().then([](test_request* request) { ++ VERIFY_ARE_EQUAL(request->m_method, methods::POST); ++ ++ VERIFY_IS_TRUE(is_application_x_www_form_urlencoded(request)); ++ ++ VERIFY_ARE_EQUAL( ++ U("Basic MTIzQUJDOjQ1NkRFRg=="), ++ request->m_headers[header_names::authorization]); ++ ++ VERIFY_ARE_EQUAL( ++ to_body_data(U("grant_type=client_credentials")), ++ request->m_body); ++ ++ VERIFY_ARE_EQUAL( ++ U("test_user_agent"), ++ get_request_user_agent(request)); ++ ++ std::map headers; ++ headers[header_names::content_type] = mime_types::application_json; ++ request->reply( ++ status_codes::OK, U(""), headers, "{\"access_token\":\"xyzzy123\",\"token_type\":\"bearer\"}"); ++ }); ++ ++ m_oauth2_config.token_from_client_credentials().wait(); ++ VERIFY_ARE_EQUAL(U("xyzzy123"), m_oauth2_config.token().access_token()); ++ VERIFY_IS_TRUE(m_oauth2_config.is_enabled()); ++ } ++ ++ // Fetch using client key & secret in request body (x-www-form-urlencoded). ++ { ++ m_scoped.server()->next_request().then([](test_request* request) { ++ VERIFY_IS_TRUE(is_application_x_www_form_urlencoded(request)); ++ ++ VERIFY_ARE_EQUAL(U(""), request->m_headers[header_names::authorization]); ++ ++ VERIFY_ARE_EQUAL( ++ to_body_data(U("grant_type=client_credentials&client_id=123ABC&client_secret=456DEF")), ++ request->m_body); ++ ++ VERIFY_ARE_EQUAL(U("test_user_agent"), get_request_user_agent(request)); ++ ++ std::map headers; ++ headers[header_names::content_type] = mime_types::application_json; ++ request->reply( ++ status_codes::OK, U(""), headers, "{\"access_token\":\"xyzzy123\",\"token_type\":\"bearer\"}"); ++ }); ++ ++ m_oauth2_config.set_token(oauth2_token()); // Clear token. ++ VERIFY_IS_FALSE(m_oauth2_config.is_enabled()); ++ ++ m_oauth2_config.set_http_basic_auth(false); ++ m_oauth2_config.token_from_client_credentials().wait(); ++ ++ VERIFY_ARE_EQUAL( ++ U("xyzzy123"), ++ m_oauth2_config.token().access_token()); ++ VERIFY_IS_TRUE(m_oauth2_config.is_enabled()); ++ } ++ } ++ + TEST_FIXTURE(oauth2_test_setup, oauth2_bearer_token) + { + m_oauth2_config.set_token(oauth2_token(U("12345678"))); +-- +2.23.3 + diff --git a/SPECS/cpprest/cpprest.spec b/SPECS/cpprest/cpprest.spec index 6c26c5e7ce5..a1f5d251a80 100644 --- a/SPECS/cpprest/cpprest.spec +++ b/SPECS/cpprest/cpprest.spec @@ -3,7 +3,7 @@ Name: cpprest Version: 2.10.14 -Release: 6%{?dist} +Release: 7%{?dist} Summary: C++ REST library Group: Applications/File License: MIT @@ -16,6 +16,8 @@ Patch1: cpprest-2.10.9-disable-outside-and-failing-tests.patch Patch2: cpprest-2.10.9-disable-tests-long-timeouts.patch # Disable test extract_floating_point, which fails on ppc64le and aarch64 Patch3: cpprest-2.10.9-disable-test-extract_floating_point.patch +# Add support for oauth2 'client_credentials' grant type. +Patch4: cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch Vendor: Microsoft Corporation Distribution: Mariner BuildRequires: boost-devel >= 1.55 @@ -50,6 +52,7 @@ Development files. %patch1 -p1 %patch2 -p1 %patch3 -p1 +%patch4 -p1 # Remove bundled sources of websocketpp rm -r Release/libs # Remove file ThirdPartyNotices.txt, which is associated to websocketpp @@ -91,6 +94,9 @@ cd Release/build.release/Binaries %changelog +* Mon Dec 14 2020 Andrew Beltrano - 2.10.14-7 +- Add cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch. + * Tue Dec 08 2020 Andrew Phelps - 2.10.14-6 - Remove -DBUILD_TESTS=OFF to allow running tests From f2b2870bb5253e883c695303ae8309aa934e6274 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Mon, 7 Dec 2020 16:55:03 -0800 Subject: [PATCH 2/4] Format spec with spec-lint suggestions. --- SPECS/cpprest/cpprest.spec | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/SPECS/cpprest/cpprest.spec b/SPECS/cpprest/cpprest.spec index a1f5d251a80..80f419ae314 100644 --- a/SPECS/cpprest/cpprest.spec +++ b/SPECS/cpprest/cpprest.spec @@ -1,13 +1,16 @@ %define major 2 %define minor 10 - +Summary: C++ REST library Name: cpprest Version: 2.10.14 Release: 7%{?dist} Summary: C++ REST library Group: Applications/File License: MIT -Url: https://github.com/Microsoft/cpprestsdk +Vendor: Microsoft Corporation +Distribution: Mariner +Group: Applications/File +URL: https://github.com/Microsoft/cpprestsdk #Source0: https://github.com/Microsoft/cpprestsdk/archive/v%{version}.tar.gz Source0: %{name}-%{version}.tar.gz # Disable outside, failing and sometimes failing tests @@ -18,13 +21,11 @@ Patch2: cpprest-2.10.9-disable-tests-long-timeouts.patch Patch3: cpprest-2.10.9-disable-test-extract_floating_point.patch # Add support for oauth2 'client_credentials' grant type. Patch4: cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch -Vendor: Microsoft Corporation -Distribution: Mariner BuildRequires: boost-devel >= 1.55 -BuildRequires: cmake >= 3.1 -BuildRequires: websocketpp-devel BuildRequires: brotli-devel +BuildRequires: cmake >= 3.1 BuildRequires: openssl >= 1.0 +BuildRequires: websocketpp-devel BuildRequires: zlib %description @@ -48,7 +49,7 @@ project aims to help C++ developers connect to and interact with services. Development files. %prep -%setup -n cpprestsdk-%{version} +%setup -q -n cpprestsdk-%{version} %patch1 -p1 %patch2 -p1 %patch3 -p1 @@ -77,7 +78,6 @@ cd Release/build.release/Binaries ./test_runner *_test.so ||: %post -p /sbin/ldconfig - %postun -p /sbin/ldconfig %files @@ -92,7 +92,6 @@ cd Release/build.release/Binaries %{_libdir}/libcpprest.so %{_libdir}/cmake/cpprestsdk - %changelog * Mon Dec 14 2020 Andrew Beltrano - 2.10.14-7 - Add cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch. From 25fea6aae508a5aca75a5aecd991938b94a8d85c Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 8 Dec 2020 14:26:58 -0800 Subject: [PATCH 3/4] Match line-endings in patch --- ...pport-for-oauth2-using-client-credentials.patch | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/SPECS/cpprest/cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch b/SPECS/cpprest/cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch index 113f14c2cbe..201461dcfaa 100644 --- a/SPECS/cpprest/cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch +++ b/SPECS/cpprest/cpprest-2.10.14-Add-support-for-oauth2-using-client-credentials.patch @@ -14,13 +14,13 @@ index c3b1a53c..3deb24a1 100644 --- a/Release/include/cpprest/details/http_constants.dat +++ b/Release/include/cpprest/details/http_constants.dat @@ -190,6 +190,7 @@ DAT(expires_in, "expires_in") - DAT(grant_type, "grant_type") - DAT(redirect_uri, "redirect_uri") - DAT(refresh_token, "refresh_token") -+DAT(client_credentials, "client_credentials") - DAT(response_type, "response_type") - DAT(scope, "scope") - DAT(state, "state") + DAT(grant_type, "grant_type") + DAT(redirect_uri, "redirect_uri") + DAT(refresh_token, "refresh_token") ++DAT(client_credentials, "client_credentials") + DAT(response_type, "response_type") + DAT(scope, "scope") + DAT(state, "state") diff --git a/Release/include/cpprest/oauth2.h b/Release/include/cpprest/oauth2.h index 693ebbe3..68a7c7b9 100644 --- a/Release/include/cpprest/oauth2.h From f3a49c090bd3d900d6f9abc1a82be6f2a26f47fe Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Mon, 14 Dec 2020 17:08:54 -0800 Subject: [PATCH 4/4] Re-incorporate spec-lint changes after rebase. --- SPECS/cpprest/cpprest.spec | 2 -- 1 file changed, 2 deletions(-) diff --git a/SPECS/cpprest/cpprest.spec b/SPECS/cpprest/cpprest.spec index 80f419ae314..7c69ceccc59 100644 --- a/SPECS/cpprest/cpprest.spec +++ b/SPECS/cpprest/cpprest.spec @@ -4,8 +4,6 @@ Summary: C++ REST library Name: cpprest Version: 2.10.14 Release: 7%{?dist} -Summary: C++ REST library -Group: Applications/File License: MIT Vendor: Microsoft Corporation Distribution: Mariner