From 350c00320d426e80483037c429d78243e3a736c1 Mon Sep 17 00:00:00 2001 From: Prashant <13349374+prashantpag26@users.noreply.github.com> Date: Fri, 13 Nov 2026 17:44:01 +0530 Subject: [PATCH] [FIX] webservice: authorization URL and scope required for the web application flow The required attribute of the scope and the authorization URL tested oauth2_flow against 'authorization_code', a value that does not exist, so they were never required for the web application flow. --- webservice/tests/test_oauth2.py | 30 +++++++++++++++++++++++++ webservice/views/webservice_backend.xml | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/webservice/tests/test_oauth2.py b/webservice/tests/test_oauth2.py index a40c8205..17fbf890 100644 --- a/webservice/tests/test_oauth2.py +++ b/webservice/tests/test_oauth2.py @@ -247,6 +247,9 @@ def test_oauth2_flow_compute_with_ui(self): ws_form.oauth2_clientid = "Test Client ID" ws_form.oauth2_client_secret = "Test Client Secret" ws_form.oauth2_token_url = f"{url}oauth2/token" + if oauth2_flow == "web_application": + ws_form.oauth2_scope = "Test Scope" + ws_form.oauth2_authorization_url = f"{url}oauth2/auth" if auth_type == "user_pwd": ws_form.username = "Test Username" ws_form.password = "Test Password" @@ -265,6 +268,9 @@ def test_oauth2_flow_compute_with_ui(self): ws_form.oauth2_clientid = "Test Client ID" ws_form.oauth2_client_secret = "Test Client Secret" ws_form.oauth2_token_url = f"{url}oauth2/token" + if oauth2_flow == "web_application": + ws_form.oauth2_scope = "Test Scope" + ws_form.oauth2_authorization_url = f"{url}oauth2/auth" ws = ws_form.save() # Check that ``oauth2_flow`` is the expected one after update only if the # ``auth_type`` is "oauth2", else it should be False @@ -272,6 +278,30 @@ def test_oauth2_flow_compute_with_ui(self): ws.oauth2_flow, oauth2_flow if ws.auth_type == "oauth2" else False ) + def test_web_application_required_fields_with_ui(self): + """The authorization URL and the scope are required for the web + application flow, the authorization redirect needs them.""" + ws_form = Form( + self.webservice.browse(), "webservice.webservice_backend_form_view" + ) + ws_form.name = "WebService Test UI" + ws_form.tech_name = "webservice_test_ui_web_application" + ws_form.protocol = "http" + ws_form.url = self.url + ws_form.auth_type = "oauth2" + ws_form.oauth2_flow = "web_application" + ws_form.oauth2_clientid = "Test Client ID" + ws_form.oauth2_client_secret = "Test Client Secret" + ws_form.oauth2_token_url = f"{self.url}oauth2/token" + with self.assertRaisesRegex(AssertionError, "oauth2_scope"): + ws_form.save() + ws_form.oauth2_scope = "Test Scope" + with self.assertRaisesRegex(AssertionError, "oauth2_authorization_url"): + ws_form.save() + ws_form.oauth2_authorization_url = f"{self.url}oauth2/auth" + ws = ws_form.save() + self.assertEqual(ws.oauth2_authorization_url, f"{self.url}oauth2/auth") + class TestWebServiceOauth2FlowReset(CommonWebService): """``oauth2_flow`` must be reset on any write, not only via the UI. diff --git a/webservice/views/webservice_backend.xml b/webservice/views/webservice_backend.xml index 87156b3f..da8a6549 100644 --- a/webservice/views/webservice_backend.xml +++ b/webservice/views/webservice_backend.xml @@ -79,12 +79,12 @@