From c83659645cba07039077b9c0ebff2c4970ea0301 Mon Sep 17 00:00:00 2001 From: Manh Nguyen Date: Wed, 4 Nov 2026 00:53:54 +0700 Subject: [PATCH] [FIX] webservice: authorization URL and scope required for the web application flow The required condition of the authorization URL and the scope used the flow value 'authorization_code', which does not exist (the value is 'web_application'), so they were never required although the authorization redirect needs them. Forward port of #197. --- webservice/tests/test_oauth2.py | 25 ++++++++++++++++++++++ webservice/views/webservice_backend.xml | 4 ++-- webservice_server_env/tests/test_oauth2.py | 6 ++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/webservice/tests/test_oauth2.py b/webservice/tests/test_oauth2.py index 1288cda8..5bb640b5 100644 --- a/webservice/tests/test_oauth2.py +++ b/webservice/tests/test_oauth2.py @@ -10,6 +10,7 @@ from oauthlib.oauth2.rfc6749.errors import InvalidGrantError from odoo import exceptions +from odoo.tests import Form from .common import CommonWebService, mock_cursor @@ -375,6 +376,30 @@ def test_fetch_token_from_auth(self): ) self.assertEqual("cool_token", token["access_token"]) + 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 6b398d92..e710fcf3 100644 --- a/webservice/views/webservice_backend.xml +++ b/webservice/views/webservice_backend.xml @@ -93,12 +93,12 @@