Skip to content

Commit 9a9c865

Browse files
committed
[ADD] webservice_client_certificate_auth: new module
1 parent 6713cd9 commit 9a9c865

File tree

16 files changed

+782
-0
lines changed

16 files changed

+782
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
==============================================
2+
WebService - Client Certificate Authentication
3+
==============================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:4a2f96ce5a7f3c69babb934fd5a9e2bb530fd01e335c3526d5f499774b59fd36
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github
20+
:target: https://github.com/OCA/web-api/tree/18.0/webservice_client_certificate_auth
21+
:alt: OCA/web-api
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/web-api-18-0/web-api-18-0-webservice_client_certificate_auth
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/web-api&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
Adds support for Client Side Certificates to the ``webservice`` module.
32+
33+
**Table of contents**
34+
35+
.. contents::
36+
:local:
37+
38+
Configuration
39+
=============
40+
41+
Certificate paths are configured via ``server_environment``. Add the
42+
configuration section matching your backend's ``tech_name`` to your
43+
server environment files:
44+
45+
::
46+
47+
[webservice_backend.my_secure_service]
48+
auth_type = client_certificate
49+
client_certificate_path = /etc/odoo/certs/client.crt
50+
# Optional: Leave empty if the private key is bundled in the certificate file
51+
client_private_key_path = /etc/odoo/certs/client.key
52+
53+
Usage
54+
=====
55+
56+
When a call is made using the backend, the adapter automatically injects
57+
the ``cert`` parameter into the underlying Python ``requests`` call
58+
based on the provided configuration:
59+
60+
- **Certificate only:** Passed as ``cert='/path/to/file'`` (a single
61+
file containing the private key and the certificate).
62+
- **Certificate and Key:** Passed as a tuple
63+
``cert=('/path/to/crt', '/path/to/key')``.
64+
65+
Warning: the private key to your local certificate must be unencrypted.
66+
Currently, ``requests`` does not support using encrypted keys.
67+
68+
See `Requests: Client Side
69+
Certificates <https://requests.readthedocs.io/en/latest/user/advanced/#client-side-certificates>`__
70+
for underlying implementation details.
71+
72+
Bug Tracker
73+
===========
74+
75+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web-api/issues>`_.
76+
In case of trouble, please check there if your issue has already been reported.
77+
If you spotted it first, help us to smash it by providing a detailed and welcomed
78+
`feedback <https://github.com/OCA/web-api/issues/new?body=module:%20webservice_client_certificate_auth%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
79+
80+
Do not contact contributors directly about support or help with technical issues.
81+
82+
Credits
83+
=======
84+
85+
Authors
86+
-------
87+
88+
* Camptocamp
89+
90+
Contributors
91+
------------
92+
93+
- Vincent Van Rossem <vincent.vanrossem@camptocamp.com>
94+
95+
Maintainers
96+
-----------
97+
98+
This module is maintained by the OCA.
99+
100+
.. image:: https://odoo-community.org/logo.png
101+
:alt: Odoo Community Association
102+
:target: https://odoo-community.org
103+
104+
OCA, or the Odoo Community Association, is a nonprofit organization whose
105+
mission is to support the collaborative development of Odoo features and
106+
promote its widespread use.
107+
108+
This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/18.0/webservice_client_certificate_auth>`_ project on GitHub.
109+
110+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import components
2+
from . import models
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "WebService - Client Certificate Authentication",
6+
"version": "18.0.1.0.0",
7+
"license": "AGPL-3",
8+
"author": "Camptocamp, Odoo Community Association (OCA)",
9+
"website": "https://github.com/OCA/web-api",
10+
"depends": ["webservice"],
11+
"data": [
12+
"views/webservice_backend.xml",
13+
],
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import request_adapter
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo.addons.component.core import Component
5+
6+
7+
class ClientCertRestRequestsAdapter(Component):
8+
_inherit = "base.requests"
9+
10+
def _request(self, method, url=None, url_params=None, **kwargs):
11+
if self.collection.auth_type == "client_certificate":
12+
# ``requests`` ``cert`` parameter accepts:
13+
# * A string: path to a file containing both certificate and private key
14+
# * A tuple: ('/path/client.cert', '/path/client.key')
15+
cert_path = self._get_cert_path()
16+
key_path = self._get_key_path()
17+
18+
if "cert" not in kwargs and cert_path:
19+
if key_path:
20+
kwargs["cert"] = (cert_path, key_path)
21+
else:
22+
kwargs["cert"] = cert_path
23+
24+
return super()._request(method, url=url, url_params=url_params, **kwargs)
25+
26+
def _get_cert_path(self):
27+
return self.collection.client_certificate_path
28+
29+
def _get_key_path(self):
30+
return self.collection.client_private_key_path
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import webservice_backend
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class WebserviceBackend(models.Model):
8+
_inherit = "webservice.backend"
9+
10+
auth_type = fields.Selection(
11+
selection_add=[("client_certificate", "Client Certificate")],
12+
ondelete={"client_certificate": lambda recs: recs.write({"auth_type": "none"})},
13+
)
14+
client_certificate_path = fields.Char(
15+
auth_type="client_certificate",
16+
)
17+
client_private_key_path = fields.Char()
18+
19+
@property
20+
def _server_env_fields(self):
21+
env_fields = super()._server_env_fields
22+
env_fields.update(
23+
{
24+
"client_certificate_path": {},
25+
"client_private_key_path": {},
26+
}
27+
)
28+
return env_fields
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Certificate paths are configured via `server_environment`.
2+
Add the configuration section matching your backend's `tech_name` to your server environment files:
3+
4+
```
5+
[webservice_backend.my_secure_service]
6+
auth_type = client_certificate
7+
client_certificate_path = /etc/odoo/certs/client.crt
8+
# Optional: Leave empty if the private key is bundled in the certificate file
9+
client_private_key_path = /etc/odoo/certs/client.key
10+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Vincent Van Rossem \<<vincent.vanrossem@camptocamp.com>\>

0 commit comments

Comments
 (0)