From 35f970ff9a27487dc658bb9b9ab604f57f1d389f Mon Sep 17 00:00:00 2001
From: "Laurent Mignon (ACSONE)"
Date: Wed, 31 Jan 2018 17:30:50 +0100
Subject: [PATCH 001/107] New generic module du define REST services
---
auth_api_key/models/__init__.py | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 auth_api_key/models/__init__.py
diff --git a/auth_api_key/models/__init__.py b/auth_api_key/models/__init__.py
new file mode 100644
index 0000000000..01b3640a45
--- /dev/null
+++ b/auth_api_key/models/__init__.py
@@ -0,0 +1,2 @@
+from . import ir_http
+from . import invader_entrypoint
From 54574c0b744af6c5ca6e00feeebad677f2e2b030 Mon Sep 17 00:00:00 2001
From: "Laurent Mignon (ACSONE)"
Date: Thu, 1 Feb 2018 00:20:26 +0100
Subject: [PATCH 002/107] auth_api_key: New module to provide authentication by
api_key
---
auth_api_key/README.rst | 85 +++++++++++++++++++++++
auth_api_key/__init__.py | 1 +
auth_api_key/__manifest__.py | 22 ++++++
auth_api_key/models/__init__.py | 3 +-
auth_api_key/models/auth_api_key.py | 49 +++++++++++++
auth_api_key/models/ir_http.py | 39 +++++++++++
auth_api_key/models/keychain_account.py | 21 ++++++
auth_api_key/security/auth_api_key.xml | 17 +++++
auth_api_key/static/description/icon.png | Bin 0 -> 9455 bytes
auth_api_key/views/auth_api_key.xml | 51 ++++++++++++++
10 files changed, 287 insertions(+), 1 deletion(-)
create mode 100644 auth_api_key/README.rst
create mode 100644 auth_api_key/__init__.py
create mode 100644 auth_api_key/__manifest__.py
create mode 100644 auth_api_key/models/auth_api_key.py
create mode 100644 auth_api_key/models/ir_http.py
create mode 100644 auth_api_key/models/keychain_account.py
create mode 100644 auth_api_key/security/auth_api_key.xml
create mode 100644 auth_api_key/static/description/icon.png
create mode 100644 auth_api_key/views/auth_api_key.xml
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
new file mode 100644
index 0000000000..f562e2611f
--- /dev/null
+++ b/auth_api_key/README.rst
@@ -0,0 +1,85 @@
+.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
+ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
+ :alt: License: AGPL-3
+
+============
+Auth Api Key
+============
+
+Authenticate http requests from an API key
+
+
+Configuration
+=============
+
+The api key must be provided by the coniguration parameter named
+'auth_api_key.api_key'.
+To apply this authentication system to your http request you must set 'api_key'
+as value for the 'auth' parameter of your route definition into your controller.
+
+ ::
+
+ class MyController(Controller):
+
+ @route('/my_service', auth='api_key', ...)
+ def my_service(self, *args, **kwargs):
+ pass
+
+Usage
+=====
+
+To use this module, you need to:
+
+#. Go to ...
+
+.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
+ :alt: Try me on Runbot
+ :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch}
+
+.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
+.. branch is "8.0" for example
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues
+`_. In case of trouble, please
+check there if your issue has already been reported. If you spotted it first,
+help us smash it by providing detailed and welcomed feedback.
+
+Credits
+=======
+
+Images
+------
+
+* Odoo Community Association: `Icon `_.
+
+Contributors
+------------
+
+* Firstname Lastname
+* Second Person
+
+Funders
+-------
+
+The development of this module has been financially supported by:
+
+* Company 1 name
+* Company 2 name
+
+Maintainer
+----------
+
+.. image:: https://odoo-community.org/logo.png
+ :alt: Odoo Community Association
+ :target: https://odoo-community.org
+
+This module is maintained by the OCA.
+
+OCA, or the Odoo Community Association, is a nonprofit organization whose
+mission is to support the collaborative development of Odoo features and
+promote its widespread use.
+
+To contribute to this module, please visit https://odoo-community.org.
diff --git a/auth_api_key/__init__.py b/auth_api_key/__init__.py
new file mode 100644
index 0000000000..0650744f6b
--- /dev/null
+++ b/auth_api_key/__init__.py
@@ -0,0 +1 @@
+from . import models
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
new file mode 100644
index 0000000000..8294eb056a
--- /dev/null
+++ b/auth_api_key/__manifest__.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Copyright 2018 ACSONE SA/NV
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+{
+ 'name': 'Auth Api Key',
+ 'summary': """
+ Authenticate http requests from an API key""",
+ 'version': '10.0.1.0.0',
+ 'license': 'AGPL-3',
+ 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
+ 'website': 'https://acsone.eu/',
+ 'depends': [
+ 'keychain'
+ ],
+ 'data': [
+ 'security/auth_api_key.xml',
+ 'views/auth_api_key.xml',
+ ],
+ 'demo': [
+ ],
+}
diff --git a/auth_api_key/models/__init__.py b/auth_api_key/models/__init__.py
index 01b3640a45..389ec3bba5 100644
--- a/auth_api_key/models/__init__.py
+++ b/auth_api_key/models/__init__.py
@@ -1,2 +1,3 @@
from . import ir_http
-from . import invader_entrypoint
+from . import keychain_account
+from . import auth_api_key
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
new file mode 100644
index 0000000000..2adf2c25bb
--- /dev/null
+++ b/auth_api_key/models/auth_api_key.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+# Copyright 2018 ACSONE SA/NV
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import api, fields, models, tools
+
+
+class AuthApiKey(models.Model):
+ _name = 'auth.api.key'
+ _inherit = 'keychain.backend'
+ _backend_name = 'auth_api_key'
+
+ @api.model
+ def _default_user_id(self):
+ return self.env.user
+
+ user_id = fields.Many2one(
+ 'res.users',
+ 'User',
+ required=True,
+ help="The user used to execute the code into Odoo when user is called "
+ "with this api key.",
+ default=_default_user_id
+ )
+
+ @api.multi
+ def _inverse_password(self):
+ self.retrieve_id_by_api_key.clear_cache(self)
+ ret = super(AuthApiKey, self)._inverse_password()
+ return ret
+
+ @api.model
+ def retrieve_from_api_key(self, api_key):
+ return self.browse(self.retrieve_id_by_api_key().get(api_key, []))
+
+ @api.model
+ @tools.ormcache('self.env.uid', 'self._backend_name', 'self._name')
+ def retrieve_id_by_api_key(self):
+ keychain_account = self.env['keychain.account']
+ keychain_accounts = keychain_account.search([
+ ('namespace', '=', self._backend_name),
+ ('technical_name', 'like', self._name)
+ ])
+ res = {}
+ for key in keychain_accounts:
+ _id = int(key.technical_name.split(',')[1])
+ api_key = key.get_password()
+ res[api_key] = _id
+ return res
diff --git a/auth_api_key/models/ir_http.py b/auth_api_key/models/ir_http.py
new file mode 100644
index 0000000000..5ae09d91d5
--- /dev/null
+++ b/auth_api_key/models/ir_http.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+# Copyright 2018 ACSONE SA/NV
+# Copyright 2017 Akretion (http://www.akretion.com).
+# @author Sébastien BEAU
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+import logging
+
+from odoo.http import request
+from odoo import models
+from werkzeug.exceptions import Unauthorized
+
+
+_logger = logging.getLogger(__name__)
+
+
+class IrHttp(models.AbstractModel):
+ _inherit = 'ir.http'
+
+ @classmethod
+ def _auth_method_api_key(cls):
+ headers = request.httprequest.environ
+ api_key = headers.get('HTTP_API_KEY')
+ if api_key:
+ request.uid = 1
+ auth_api_key = request.env['auth.api.key'].retrieve_from_api_key(
+ api_key
+ )
+ if api_key:
+ # reset _env on the request since we change the uid...
+ # the next call to env will instantiate an new
+ # odoo.api.Environment with the user defined on the
+ # auth.api_key
+ request._env = None
+ request.uid = auth_api_key.user_id.id
+ request.auth_api_key = auth_api_key
+ return True
+ _logger.error("Wrong HTTP_API_KEY, access denied")
+ raise Unauthorized("Access denied")
diff --git a/auth_api_key/models/keychain_account.py b/auth_api_key/models/keychain_account.py
new file mode 100644
index 0000000000..02f46c76a3
--- /dev/null
+++ b/auth_api_key/models/keychain_account.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Copyright 2018 ACSONE SA/NV
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import api, fields, models
+
+
+class KeychainAccount(models.Model):
+
+ _inherit = 'keychain.account'
+
+ namespace = fields.Selection(
+ selection_add=[('auth_api_key', 'Search Engine Backend')])
+
+ @api.multi
+ def _auth_api_key_validate_data(self, data):
+ return True
+
+ @api.multi
+ def _auth_api_key_init_data(self):
+ return {}
diff --git a/auth_api_key/security/auth_api_key.xml b/auth_api_key/security/auth_api_key.xml
new file mode 100644
index 0000000000..2ad7762da0
--- /dev/null
+++ b/auth_api_key/security/auth_api_key.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ auth.api.key access manage
+
+
+
+
+
+
+
+
+
diff --git a/auth_api_key/static/description/icon.png b/auth_api_key/static/description/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d
GIT binary patch
literal 9455
zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~!
zVpnB`o+K7|Al`Q_U;eD$B
zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA
z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__
zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_
zj--gtp&|K1#58Yz*AHCTMziU1Jzt_jG0I@qAOHsk$2}yTmVkBp_eHuY$A9)>P6o~I
z%aQ?!(GqeQ-Y+b0I(m9pwgi(IIZZzsbMv+9w{PFtd_<_(LA~0H(xz{=FhLB@(1&qHA5EJw1>>=%q2f&^X>IQ{!GJ4e9U
z&KlB)z(84HmNgm2hg2C0>WM{E(DdPr+EeU_N@57;PC2&DmGFW_9kP&%?X4}+xWi)(
z;)z%wI5>D4a*5XwD)P--sPkoY(a~WBw;E~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oKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq
zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t<
z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k
z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp
z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{}
zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N
Xviia!U7SGha1wx#SCgwmn*{w2TRX*I
literal 0
HcmV?d00001
diff --git a/auth_api_key/views/auth_api_key.xml b/auth_api_key/views/auth_api_key.xml
new file mode 100644
index 0000000000..6937bab749
--- /dev/null
+++ b/auth_api_key/views/auth_api_key.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+ auth.api.key.form (in auth_api_key)
+ auth.api.key
+
+
+
+
+
+
+
+ auth.api.key.tree (in auth_api_key)
+ auth.api.key
+
+
+
+
+
+
+
+
+ Auth Api Key
+ auth.api.key
+ tree,form
+ []
+ {}
+
+
+
+ Auth Api Key
+
+
+
+
+
+
From 6df5abd82981a690c6da8b6db2e9f0fdf18f2080 Mon Sep 17 00:00:00 2001
From: "Laurent Mignon (ACSONE)"
Date: Fri, 2 Feb 2018 16:26:45 +0100
Subject: [PATCH 003/107] auth_api_key: Remove useless code
---
auth_api_key/models/auth_api_key.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 2adf2c25bb..7528db41de 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -26,8 +26,7 @@ def _default_user_id(self):
@api.multi
def _inverse_password(self):
self.retrieve_id_by_api_key.clear_cache(self)
- ret = super(AuthApiKey, self)._inverse_password()
- return ret
+ return super(AuthApiKey, self)._inverse_password()
@api.model
def retrieve_from_api_key(self, api_key):
From 8e40120f2cc6e578138e640fa62940655c70c1a8 Mon Sep 17 00:00:00 2001
From: "Denis Robinet (ACSONE)"
Date: Mon, 19 Feb 2018 15:30:01 +0100
Subject: [PATCH 004/107] Update the auth_api_key for keychan 10.0.2 (renamed
method)
---
auth_api_key/models/auth_api_key.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 7528db41de..8a7d401712 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -43,6 +43,6 @@ def retrieve_id_by_api_key(self):
res = {}
for key in keychain_accounts:
_id = int(key.technical_name.split(',')[1])
- api_key = key.get_password()
+ api_key = key._get_password()
res[api_key] = _id
return res
From 52dd8894d5333e685c0be0464b7e1953eb3e5d5f Mon Sep 17 00:00:00 2001
From: "Denis Robinet (ACSONE)"
Date: Mon, 19 Feb 2018 15:31:24 +0100
Subject: [PATCH 005/107] Fix the authentification method and show the user_id
on the form
---
auth_api_key/models/ir_http.py | 2 +-
auth_api_key/views/auth_api_key.xml | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/auth_api_key/models/ir_http.py b/auth_api_key/models/ir_http.py
index 5ae09d91d5..6e77c0738b 100644
--- a/auth_api_key/models/ir_http.py
+++ b/auth_api_key/models/ir_http.py
@@ -26,7 +26,7 @@ def _auth_method_api_key(cls):
auth_api_key = request.env['auth.api.key'].retrieve_from_api_key(
api_key
)
- if api_key:
+ if auth_api_key:
# reset _env on the request since we change the uid...
# the next call to env will instantiate an new
# odoo.api.Environment with the user defined on the
diff --git a/auth_api_key/views/auth_api_key.xml b/auth_api_key/views/auth_api_key.xml
index 6937bab749..eca677d51e 100644
--- a/auth_api_key/views/auth_api_key.xml
+++ b/auth_api_key/views/auth_api_key.xml
@@ -15,6 +15,7 @@
+
From ede3c04337749ba6c2139860d52df36e679aa661 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20BEAU?=
Date: Sun, 25 Feb 2018 19:39:24 +0100
Subject: [PATCH 006/107] refactor code in order to use generic code from
base_rest instead of custom one from shopinvader
---
auth_api_key/models/ir_http.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/auth_api_key/models/ir_http.py b/auth_api_key/models/ir_http.py
index 6e77c0738b..dd777c239a 100644
--- a/auth_api_key/models/ir_http.py
+++ b/auth_api_key/models/ir_http.py
@@ -8,7 +8,7 @@
from odoo.http import request
from odoo import models
-from werkzeug.exceptions import Unauthorized
+from odoo.exceptions import AccessDenied
_logger = logging.getLogger(__name__)
@@ -36,4 +36,4 @@ def _auth_method_api_key(cls):
request.auth_api_key = auth_api_key
return True
_logger.error("Wrong HTTP_API_KEY, access denied")
- raise Unauthorized("Access denied")
+ raise AccessDenied()
From c97e7b3ae6a12d019c25a9f75439c21b58b379ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20BEAU?=
Date: Wed, 29 Aug 2018 09:05:14 +0200
Subject: [PATCH 007/107] fix wrong name in selection box
---
auth_api_key/models/keychain_account.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/auth_api_key/models/keychain_account.py b/auth_api_key/models/keychain_account.py
index 02f46c76a3..3c919fa458 100644
--- a/auth_api_key/models/keychain_account.py
+++ b/auth_api_key/models/keychain_account.py
@@ -10,7 +10,7 @@ class KeychainAccount(models.Model):
_inherit = 'keychain.account'
namespace = fields.Selection(
- selection_add=[('auth_api_key', 'Search Engine Backend')])
+ selection_add=[('auth_api_key', 'Authentification Api key')])
@api.multi
def _auth_api_key_validate_data(self, data):
From ff092b860a48940f420e56ea5ab24360365deea8 Mon Sep 17 00:00:00 2001
From: hparfr
Date: Wed, 17 Oct 2018 12:51:51 +0200
Subject: [PATCH 008/107] Since keychain 10.0.2.0.1 there is a default
validation method
---
auth_api_key/models/keychain_account.py | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/auth_api_key/models/keychain_account.py b/auth_api_key/models/keychain_account.py
index 3c919fa458..80168d751d 100644
--- a/auth_api_key/models/keychain_account.py
+++ b/auth_api_key/models/keychain_account.py
@@ -2,7 +2,7 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import api, fields, models
+from odoo import fields, models
class KeychainAccount(models.Model):
@@ -11,11 +11,3 @@ class KeychainAccount(models.Model):
namespace = fields.Selection(
selection_add=[('auth_api_key', 'Authentification Api key')])
-
- @api.multi
- def _auth_api_key_validate_data(self, data):
- return True
-
- @api.multi
- def _auth_api_key_init_data(self):
- return {}
From 06fc2fa72e907332080023324e19ccb47a10f4ed Mon Sep 17 00:00:00 2001
From: Quentin Groulard
Date: Tue, 6 Nov 2018 12:34:52 +0100
Subject: [PATCH 009/107] Keychain removed
Get rid of keychain dependency
---
auth_api_key/__manifest__.py | 24 ++++------
auth_api_key/models/__init__.py | 1 -
auth_api_key/models/auth_api_key.py | 61 ++++++++++---------------
auth_api_key/models/ir_http.py | 12 ++---
auth_api_key/models/keychain_account.py | 13 ------
auth_api_key/readme/CONFIGURE.rst | 2 +
auth_api_key/readme/CONTRIBUTORS.rst | 4 ++
auth_api_key/readme/DESCRIPTION.rst | 1 +
auth_api_key/readme/USAGE.rst | 9 ++++
auth_api_key/security/auth_api_key.xml | 17 -------
auth_api_key/tests/__init__.py | 1 +
auth_api_key/tests/test_auth_api_key.py | 35 ++++++++++++++
auth_api_key/views/auth_api_key.xml | 52 ---------------------
13 files changed, 90 insertions(+), 142 deletions(-)
delete mode 100644 auth_api_key/models/keychain_account.py
create mode 100644 auth_api_key/readme/CONFIGURE.rst
create mode 100644 auth_api_key/readme/CONTRIBUTORS.rst
create mode 100644 auth_api_key/readme/DESCRIPTION.rst
create mode 100644 auth_api_key/readme/USAGE.rst
delete mode 100644 auth_api_key/security/auth_api_key.xml
create mode 100644 auth_api_key/tests/__init__.py
create mode 100644 auth_api_key/tests/test_auth_api_key.py
delete mode 100644 auth_api_key/views/auth_api_key.xml
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index 8294eb056a..7b68da7c41 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -3,20 +3,14 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
- 'name': 'Auth Api Key',
- 'summary': """
+ "name": "Auth Api Key",
+ "summary": """
Authenticate http requests from an API key""",
- 'version': '10.0.1.0.0',
- 'license': 'AGPL-3',
- 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
- 'website': 'https://acsone.eu/',
- 'depends': [
- 'keychain'
- ],
- 'data': [
- 'security/auth_api_key.xml',
- 'views/auth_api_key.xml',
- ],
- 'demo': [
- ],
+ "version": "10.0.1.0.0",
+ "license": "AGPL-3",
+ "author": "ACSONE SA/NV,Odoo Community Association (OCA)",
+ "website": "https://acsone.eu/",
+ "depends": ["server_environment"],
+ "data": [],
+ "demo": [],
}
diff --git a/auth_api_key/models/__init__.py b/auth_api_key/models/__init__.py
index 389ec3bba5..dee3379fea 100644
--- a/auth_api_key/models/__init__.py
+++ b/auth_api_key/models/__init__.py
@@ -1,3 +1,2 @@
from . import ir_http
-from . import keychain_account
from . import auth_api_key
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 8a7d401712..733bd10f03 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -4,45 +4,32 @@
from odoo import api, fields, models, tools
+from odoo.addons.server_environment import serv_config
-class AuthApiKey(models.Model):
- _name = 'auth.api.key'
- _inherit = 'keychain.backend'
- _backend_name = 'auth_api_key'
+from odoo.exceptions import ValidationError, AccessError
- @api.model
- def _default_user_id(self):
- return self.env.user
-
- user_id = fields.Many2one(
- 'res.users',
- 'User',
- required=True,
- help="The user used to execute the code into Odoo when user is called "
- "with this api key.",
- default=_default_user_id
- )
-
- @api.multi
- def _inverse_password(self):
- self.retrieve_id_by_api_key.clear_cache(self)
- return super(AuthApiKey, self)._inverse_password()
- @api.model
- def retrieve_from_api_key(self, api_key):
- return self.browse(self.retrieve_id_by_api_key().get(api_key, []))
+class AuthApiKey(models.TransientModel):
+ _name = "auth.api.key"
@api.model
- @tools.ormcache('self.env.uid', 'self._backend_name', 'self._name')
- def retrieve_id_by_api_key(self):
- keychain_account = self.env['keychain.account']
- keychain_accounts = keychain_account.search([
- ('namespace', '=', self._backend_name),
- ('technical_name', 'like', self._name)
- ])
- res = {}
- for key in keychain_accounts:
- _id = int(key.technical_name.split(',')[1])
- api_key = key._get_password()
- res[api_key] = _id
- return res
+ @tools.ormcache("api_key")
+ def _retrieve_uid_from_api_key(self, api_key):
+ if not self.env.user.has_group("base.group_system"):
+ raise AccessError("User is not allowed")
+
+ for section in serv_config.sections():
+ if section.startswith("api_key_") and serv_config.has_option(
+ section, "key"
+ ):
+ if api_key != serv_config.get(section, "key"):
+ continue
+
+ login_name = serv_config.get(section, "user")
+ uid = self.env["res.users"].search([("login", "=", login_name)]).id
+
+ if not uid:
+ raise ValidationError("No user found with login %s" % login_name)
+
+ return uid
+ return False
diff --git a/auth_api_key/models/ir_http.py b/auth_api_key/models/ir_http.py
index dd777c239a..dd1483a644 100644
--- a/auth_api_key/models/ir_http.py
+++ b/auth_api_key/models/ir_http.py
@@ -15,24 +15,22 @@
class IrHttp(models.AbstractModel):
- _inherit = 'ir.http'
+ _inherit = "ir.http"
@classmethod
def _auth_method_api_key(cls):
headers = request.httprequest.environ
- api_key = headers.get('HTTP_API_KEY')
+ api_key = headers.get("HTTP_API_KEY")
if api_key:
request.uid = 1
- auth_api_key = request.env['auth.api.key'].retrieve_from_api_key(
- api_key
- )
- if auth_api_key:
+ uid = request.env["auth.api.key"].retrieve_uid_from_api_key(api_key)
+ if uid:
# reset _env on the request since we change the uid...
# the next call to env will instantiate an new
# odoo.api.Environment with the user defined on the
# auth.api_key
request._env = None
- request.uid = auth_api_key.user_id.id
+ request.uid = uid
request.auth_api_key = auth_api_key
return True
_logger.error("Wrong HTTP_API_KEY, access denied")
diff --git a/auth_api_key/models/keychain_account.py b/auth_api_key/models/keychain_account.py
deleted file mode 100644
index 80168d751d..0000000000
--- a/auth_api_key/models/keychain_account.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2018 ACSONE SA/NV
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-
-from odoo import fields, models
-
-
-class KeychainAccount(models.Model):
-
- _inherit = 'keychain.account'
-
- namespace = fields.Selection(
- selection_add=[('auth_api_key', 'Authentification Api key')])
diff --git a/auth_api_key/readme/CONFIGURE.rst b/auth_api_key/readme/CONFIGURE.rst
new file mode 100644
index 0000000000..0c2c0538e5
--- /dev/null
+++ b/auth_api_key/readme/CONFIGURE.rst
@@ -0,0 +1,2 @@
+The api key must be provided by the coniguration parameter named
+'api_key_*.key', and the user under the same option 'api_key_*.user'.
\ No newline at end of file
diff --git a/auth_api_key/readme/CONTRIBUTORS.rst b/auth_api_key/readme/CONTRIBUTORS.rst
new file mode 100644
index 0000000000..765b551496
--- /dev/null
+++ b/auth_api_key/readme/CONTRIBUTORS.rst
@@ -0,0 +1,4 @@
+* Denis Robinet <>
+* Laurent Mignon <>
+* Quentin Groulard <>
+* Sébastien Beau <>
\ No newline at end of file
diff --git a/auth_api_key/readme/DESCRIPTION.rst b/auth_api_key/readme/DESCRIPTION.rst
new file mode 100644
index 0000000000..dd9562ef54
--- /dev/null
+++ b/auth_api_key/readme/DESCRIPTION.rst
@@ -0,0 +1 @@
+Authenticate http requests from an API key.
\ No newline at end of file
diff --git a/auth_api_key/readme/USAGE.rst b/auth_api_key/readme/USAGE.rst
new file mode 100644
index 0000000000..4464ca59c9
--- /dev/null
+++ b/auth_api_key/readme/USAGE.rst
@@ -0,0 +1,9 @@
+To apply this authentication system to your http request you must set 'api_key'
+as value for the 'auth' parameter of your route definition into your controller.
+
+
+ class MyController(Controller):
+
+ @route('/my_service', auth='api_key', ...)
+ def my_service(self, *args, **kwargs):
+ pass
\ No newline at end of file
diff --git a/auth_api_key/security/auth_api_key.xml b/auth_api_key/security/auth_api_key.xml
deleted file mode 100644
index 2ad7762da0..0000000000
--- a/auth_api_key/security/auth_api_key.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
- auth.api.key access manage
-
-
-
-
-
-
-
-
-
diff --git a/auth_api_key/tests/__init__.py b/auth_api_key/tests/__init__.py
new file mode 100644
index 0000000000..56e3e32a3a
--- /dev/null
+++ b/auth_api_key/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_auth_api_key
diff --git a/auth_api_key/tests/test_auth_api_key.py b/auth_api_key/tests/test_auth_api_key.py
new file mode 100644
index 0000000000..dd43eb4f30
--- /dev/null
+++ b/auth_api_key/tests/test_auth_api_key.py
@@ -0,0 +1,35 @@
+from odoo.tests.common import TransactionCase
+from odoo.addons.server_environment import serv_config
+from odoo.exceptions import ValidationError, AccessError
+
+
+class TestAuthApiKey(TransactionCase):
+ @classmethod
+ def setUpClass(cls, *args, **kwargs):
+ super(TestAuthApiKey, cls).setUpClass(*args, **kwargs)
+
+ serv_config.add_section("api_key_good")
+ serv_config.set("api_key_good", "user", "demo")
+ serv_config.set("api_key_good", "key", "api_right_key")
+ serv_config.add_section("api_key_bad")
+ serv_config.set("api_key_bad", "user", "not_demo")
+ serv_config.set("api_key_bad", "key", "api_wrong_key")
+
+ def test_lookup(self):
+ demo_user = self.env.ref("base.user_demo")
+ self.assertEqual(
+ self.env["auth.api.key"]._retrieve_uid_from_api_key("api_right_key"),
+ demo_user.id,
+ )
+
+ def test_wrong_key(self):
+ with self.assertRaises(ValidationError), self.env.cr.savepoint():
+ self.env["auth.api.key"]._retrieve_uid_from_api_key("api_wrong_key")
+
+ def test_user_not_allowed(self):
+ demo_user = self.env.ref("base.user_demo")
+ with self.assertRaises(AccessError), self.env.cr.savepoint():
+ self.env["auth.api.key"].sudo(user=demo_user)._retrieve_uid_from_api_key(
+ "api_wrong_key"
+ )
+
diff --git a/auth_api_key/views/auth_api_key.xml b/auth_api_key/views/auth_api_key.xml
deleted file mode 100644
index eca677d51e..0000000000
--- a/auth_api_key/views/auth_api_key.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-
-
-
-
- auth.api.key.form (in auth_api_key)
- auth.api.key
-
-
-
-
-
-
-
- auth.api.key.tree (in auth_api_key)
- auth.api.key
-
-
-
-
-
-
-
-
- Auth Api Key
- auth.api.key
- tree,form
- []
- {}
-
-
-
- Auth Api Key
-
-
-
-
-
-
From 7ed704e18a96929f5edc3b7561b4085b0c014fbd Mon Sep 17 00:00:00 2001
From: Quentin Groulard
Date: Thu, 8 Nov 2018 11:06:58 +0100
Subject: [PATCH 010/107] Update Readme with more details
---
auth_api_key/README.rst | 85 ----------------------------
auth_api_key/readme/CONFIGURE.rst | 10 +++-
auth_api_key/readme/CONTRIBUTORS.rst | 8 +--
auth_api_key/readme/DESCRIPTION.rst | 6 +-
4 files changed, 17 insertions(+), 92 deletions(-)
delete mode 100644 auth_api_key/README.rst
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
deleted file mode 100644
index f562e2611f..0000000000
--- a/auth_api_key/README.rst
+++ /dev/null
@@ -1,85 +0,0 @@
-.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
- :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
- :alt: License: AGPL-3
-
-============
-Auth Api Key
-============
-
-Authenticate http requests from an API key
-
-
-Configuration
-=============
-
-The api key must be provided by the coniguration parameter named
-'auth_api_key.api_key'.
-To apply this authentication system to your http request you must set 'api_key'
-as value for the 'auth' parameter of your route definition into your controller.
-
- ::
-
- class MyController(Controller):
-
- @route('/my_service', auth='api_key', ...)
- def my_service(self, *args, **kwargs):
- pass
-
-Usage
-=====
-
-To use this module, you need to:
-
-#. Go to ...
-
-.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
- :alt: Try me on Runbot
- :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch}
-
-.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
-.. branch is "8.0" for example
-
-Bug Tracker
-===========
-
-Bugs are tracked on `GitHub Issues
-`_. In case of trouble, please
-check there if your issue has already been reported. If you spotted it first,
-help us smash it by providing detailed and welcomed feedback.
-
-Credits
-=======
-
-Images
-------
-
-* Odoo Community Association: `Icon `_.
-
-Contributors
-------------
-
-* Firstname Lastname
-* Second Person
-
-Funders
--------
-
-The development of this module has been financially supported by:
-
-* Company 1 name
-* Company 2 name
-
-Maintainer
-----------
-
-.. image:: https://odoo-community.org/logo.png
- :alt: Odoo Community Association
- :target: https://odoo-community.org
-
-This module is maintained by the OCA.
-
-OCA, or the Odoo Community Association, is a nonprofit organization whose
-mission is to support the collaborative development of Odoo features and
-promote its widespread use.
-
-To contribute to this module, please visit https://odoo-community.org.
diff --git a/auth_api_key/readme/CONFIGURE.rst b/auth_api_key/readme/CONFIGURE.rst
index 0c2c0538e5..0d403e1f65 100644
--- a/auth_api_key/readme/CONFIGURE.rst
+++ b/auth_api_key/readme/CONFIGURE.rst
@@ -1,2 +1,8 @@
-The api key must be provided by the coniguration parameter named
-'api_key_*.key', and the user under the same option 'api_key_*.user'.
\ No newline at end of file
+The api key must be provided by the configuration parameter named
+'api_key_*.key', and the user under the same option 'api_key_*.user'.
+
+For instance :
+
+ [api_key_mykey]
+ key=my_api_key
+ user=my_user
\ No newline at end of file
diff --git a/auth_api_key/readme/CONTRIBUTORS.rst b/auth_api_key/readme/CONTRIBUTORS.rst
index 765b551496..14d8f94b83 100644
--- a/auth_api_key/readme/CONTRIBUTORS.rst
+++ b/auth_api_key/readme/CONTRIBUTORS.rst
@@ -1,4 +1,4 @@
-* Denis Robinet <>
-* Laurent Mignon <>
-* Quentin Groulard <>
-* Sébastien Beau <>
\ No newline at end of file
+* Denis Robinet
+* Laurent Mignon
+* Quentin Groulard
+* Sébastien Beau
\ No newline at end of file
diff --git a/auth_api_key/readme/DESCRIPTION.rst b/auth_api_key/readme/DESCRIPTION.rst
index dd9562ef54..575f75544b 100644
--- a/auth_api_key/readme/DESCRIPTION.rst
+++ b/auth_api_key/readme/DESCRIPTION.rst
@@ -1 +1,5 @@
-Authenticate http requests from an API key.
\ No newline at end of file
+Authenticate http requests from an API key.
+
+API keys are codes passed in (in the http header API-KEY) by programs calling an API in order to identify -in this case- the calling program's user.
+
+Take care while using this kind of mechanism since information into http headers are visible in clear. Thus, use it only to authenticate requests from known sources. For unknown sources, it is a good practice to filter out this header at proxy level.
\ No newline at end of file
From b746c221d910f3b93725d36a8aeeb2bf6167fdcb Mon Sep 17 00:00:00 2001
From: qgroulard <43472442+qgroulard@users.noreply.github.com>
Date: Thu, 8 Nov 2018 11:22:06 +0100
Subject: [PATCH 011/107] Quick fix CONFIGURE.rst
---
auth_api_key/readme/CONFIGURE.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/auth_api_key/readme/CONFIGURE.rst b/auth_api_key/readme/CONFIGURE.rst
index 0d403e1f65..5118d0b936 100644
--- a/auth_api_key/readme/CONFIGURE.rst
+++ b/auth_api_key/readme/CONFIGURE.rst
@@ -2,7 +2,7 @@ The api key must be provided by the configuration parameter named
'api_key_*.key', and the user under the same option 'api_key_*.user'.
For instance :
-
+::
[api_key_mykey]
key=my_api_key
- user=my_user
\ No newline at end of file
+ user=my_user
From de14ad0e20e23e8f43ab8d8cad6ba09bfc78d6d1 Mon Sep 17 00:00:00 2001
From: qgroulard <43472442+qgroulard@users.noreply.github.com>
Date: Thu, 8 Nov 2018 11:32:09 +0100
Subject: [PATCH 012/107] Developmet status: Beta
---
auth_api_key/__manifest__.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index 7b68da7c41..c0680ffcc2 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -10,6 +10,7 @@
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://acsone.eu/",
+ "development_status": "Beta",
"depends": ["server_environment"],
"data": [],
"demo": [],
From d00d90c332a0da2cb80afac3ced518a5591a0d1f Mon Sep 17 00:00:00 2001
From: "Laurent Mignon (ACSONE)"
Date: Tue, 13 Nov 2018 11:32:39 +0100
Subject: [PATCH 013/107] [FIX] auth_api_key: fix api and flake8
---
auth_api_key/README.rst | 108 +++++
auth_api_key/models/auth_api_key.py | 12 +-
auth_api_key/models/ir_http.py | 5 +-
auth_api_key/readme/CONFIGURE.rst | 4 +-
auth_api_key/readme/USAGE.rst | 3 +-
auth_api_key/static/description/index.html | 449 +++++++++++++++++++++
auth_api_key/tests/test_auth_api_key.py | 15 +-
7 files changed, 581 insertions(+), 15 deletions(-)
create mode 100644 auth_api_key/README.rst
create mode 100644 auth_api_key/static/description/index.html
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
new file mode 100644
index 0000000000..cbdf2d6b2d
--- /dev/null
+++ b/auth_api_key/README.rst
@@ -0,0 +1,108 @@
+============
+Auth Api Key
+============
+
+.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ !! This file is generated by oca-gen-addon-readme !!
+ !! changes will be overwritten. !!
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
+ :target: https://odoo-community.org/page/development-status
+ :alt: Beta
+.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
+ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
+ :alt: License: AGPL-3
+.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
+ :target: https://github.com/OCA/server-auth/tree/10.0/auth_api_key
+ :alt: OCA/server-auth
+.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
+ :target: https://translation.odoo-community.org/projects/server-auth-10-0/server-auth-10-0-auth_api_key
+ :alt: Translate me on Weblate
+.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
+ :target: https://runbot.odoo-community.org/runbot/251/10.0
+ :alt: Try me on Runbot
+
+|badge1| |badge2| |badge3| |badge4| |badge5|
+
+Authenticate http requests from an API key.
+
+API keys are codes passed in (in the http header API-KEY) by programs calling an API in order to identify -in this case- the calling program's user.
+
+Take care while using this kind of mechanism since information into http headers are visible in clear. Thus, use it only to authenticate requests from known sources. For unknown sources, it is a good practice to filter out this header at proxy level.
+
+**Table of contents**
+
+.. contents::
+ :local:
+
+Configuration
+=============
+
+The api key must be provided by the configuration parameter named
+'api_key_*.key', and the user under the same option 'api_key_*.user'.
+
+For instance :
+
+.. code-block:: ini
+
+ [api_key_mykey]
+ key=my_api_key
+ user=my_user
+
+Usage
+=====
+
+To apply this authentication system to your http request you must set 'api_key'
+as value for the 'auth' parameter of your route definition into your controller.
+
+.. code-block:: python
+
+ class MyController(Controller):
+
+ @route('/my_service', auth='api_key', ...)
+ def my_service(self, *args, **kwargs):
+ pass
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues `_.
+In case of trouble, please check there if your issue has already been reported.
+If you spotted it first, help us smashing it by providing a detailed and welcomed
+`feedback `_.
+
+Do not contact contributors directly about support or help with technical issues.
+
+Credits
+=======
+
+Authors
+~~~~~~~
+
+* ACSONE SA/NV
+
+Contributors
+~~~~~~~~~~~~
+
+* Denis Robinet
+* Laurent Mignon
+* Quentin Groulard
+* Sébastien Beau
+
+Maintainers
+~~~~~~~~~~~
+
+This module is maintained by the OCA.
+
+.. image:: https://odoo-community.org/logo.png
+ :alt: Odoo Community Association
+ :target: https://odoo-community.org
+
+OCA, or the Odoo Community Association, is a nonprofit organization whose
+mission is to support the collaborative development of Odoo features and
+promote its widespread use.
+
+This module is part of the `OCA/server-auth `_ project on GitHub.
+
+You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 733bd10f03..4b8efd52d8 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -2,7 +2,7 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import api, fields, models, tools
+from odoo import api, models, tools, _
from odoo.addons.server_environment import serv_config
@@ -16,20 +16,22 @@ class AuthApiKey(models.TransientModel):
@tools.ormcache("api_key")
def _retrieve_uid_from_api_key(self, api_key):
if not self.env.user.has_group("base.group_system"):
- raise AccessError("User is not allowed")
+ raise AccessError(_("User is not allowed"))
for section in serv_config.sections():
if section.startswith("api_key_") and serv_config.has_option(
- section, "key"
+ section, "key"
):
if api_key != serv_config.get(section, "key"):
continue
login_name = serv_config.get(section, "user")
- uid = self.env["res.users"].search([("login", "=", login_name)]).id
+ uid = self.env["res.users"].search(
+ [("login", "=", login_name)]).id
if not uid:
- raise ValidationError("No user found with login %s" % login_name)
+ raise ValidationError(
+ _("No user found with login %s") % login_name)
return uid
return False
diff --git a/auth_api_key/models/ir_http.py b/auth_api_key/models/ir_http.py
index dd1483a644..d79da075c8 100644
--- a/auth_api_key/models/ir_http.py
+++ b/auth_api_key/models/ir_http.py
@@ -23,7 +23,8 @@ def _auth_method_api_key(cls):
api_key = headers.get("HTTP_API_KEY")
if api_key:
request.uid = 1
- uid = request.env["auth.api.key"].retrieve_uid_from_api_key(api_key)
+ uid = request.env["auth.api.key"]._retrieve_uid_from_api_key(
+ api_key)
if uid:
# reset _env on the request since we change the uid...
# the next call to env will instantiate an new
@@ -31,7 +32,7 @@ def _auth_method_api_key(cls):
# auth.api_key
request._env = None
request.uid = uid
- request.auth_api_key = auth_api_key
+ request.auth_api_key = api_key
return True
_logger.error("Wrong HTTP_API_KEY, access denied")
raise AccessDenied()
diff --git a/auth_api_key/readme/CONFIGURE.rst b/auth_api_key/readme/CONFIGURE.rst
index 5118d0b936..d65bfb4dba 100644
--- a/auth_api_key/readme/CONFIGURE.rst
+++ b/auth_api_key/readme/CONFIGURE.rst
@@ -2,7 +2,9 @@ The api key must be provided by the configuration parameter named
'api_key_*.key', and the user under the same option 'api_key_*.user'.
For instance :
-::
+
+.. code-block:: ini
+
[api_key_mykey]
key=my_api_key
user=my_user
diff --git a/auth_api_key/readme/USAGE.rst b/auth_api_key/readme/USAGE.rst
index 4464ca59c9..d8ff4460eb 100644
--- a/auth_api_key/readme/USAGE.rst
+++ b/auth_api_key/readme/USAGE.rst
@@ -1,9 +1,10 @@
To apply this authentication system to your http request you must set 'api_key'
as value for the 'auth' parameter of your route definition into your controller.
+.. code-block:: python
class MyController(Controller):
@route('/my_service', auth='api_key', ...)
def my_service(self, *args, **kwargs):
- pass
\ No newline at end of file
+ pass
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
new file mode 100644
index 0000000000..c5d2d31987
--- /dev/null
+++ b/auth_api_key/static/description/index.html
@@ -0,0 +1,449 @@
+
+
+
+
+
+
+Auth Api Key
+
+
+
+
+
Auth Api Key
+
+
+
+
Authenticate http requests from an API key.
+
API keys are codes passed in (in the http header API-KEY) by programs calling an API in order to identify -in this case- the calling program’s user.
+
Take care while using this kind of mechanism since information into http headers are visible in clear. Thus, use it only to authenticate requests from known sources. For unknown sources, it is a good practice to filter out this header at proxy level.
To apply this authentication system to your http request you must set ‘api_key’
+as value for the ‘auth’ parameter of your route definition into your controller.
Bugs are tracked on GitHub Issues.
+In case of trouble, please check there if your issue has already been reported.
+If you spotted it first, help us smashing it by providing a detailed and welcomed
+feedback.
+
Do not contact contributors directly about support or help with technical issues.
OCA, or the Odoo Community Association, is a nonprofit organization whose
+mission is to support the collaborative development of Odoo features and
+promote its widespread use.
+
This module is part of the OCA/server-auth project on GitHub.
+
+
diff --git a/auth_api_key/tests/test_auth_api_key.py b/auth_api_key/tests/test_auth_api_key.py
index dd43eb4f30..284a5aeba9 100644
--- a/auth_api_key/tests/test_auth_api_key.py
+++ b/auth_api_key/tests/test_auth_api_key.py
@@ -1,3 +1,6 @@
+# -*- coding: utf-8 -*-
+# Copyright 2018 ACSONE SA/NV
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
from odoo.addons.server_environment import serv_config
from odoo.exceptions import ValidationError, AccessError
@@ -18,18 +21,18 @@ def setUpClass(cls, *args, **kwargs):
def test_lookup(self):
demo_user = self.env.ref("base.user_demo")
self.assertEqual(
- self.env["auth.api.key"]._retrieve_uid_from_api_key("api_right_key"),
+ self.env["auth.api.key"]._retrieve_uid_from_api_key(
+ "api_right_key"),
demo_user.id,
)
def test_wrong_key(self):
with self.assertRaises(ValidationError), self.env.cr.savepoint():
- self.env["auth.api.key"]._retrieve_uid_from_api_key("api_wrong_key")
+ self.env["auth.api.key"]._retrieve_uid_from_api_key(
+ "api_wrong_key")
def test_user_not_allowed(self):
demo_user = self.env.ref("base.user_demo")
with self.assertRaises(AccessError), self.env.cr.savepoint():
- self.env["auth.api.key"].sudo(user=demo_user)._retrieve_uid_from_api_key(
- "api_wrong_key"
- )
-
+ self.env["auth.api.key"].sudo(user=demo_user).\
+ _retrieve_uid_from_api_key("api_wrong_key")
From 5fb3429ce2f78f5b29a2bf87a8beccfd86f1d874 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?=
Date: Tue, 20 Nov 2018 17:58:49 +0100
Subject: [PATCH 014/107] [MIG] server_auth from 10 to 12
---
auth_api_key/__manifest__.py | 2 +-
auth_api_key/models/auth_api_key.py | 1 -
auth_api_key/models/ir_http.py | 1 -
auth_api_key/tests/test_auth_api_key.py | 1 -
4 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index c0680ffcc2..ae027c0310 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -6,7 +6,7 @@
"name": "Auth Api Key",
"summary": """
Authenticate http requests from an API key""",
- "version": "10.0.1.0.0",
+ "version": "12.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://acsone.eu/",
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 4b8efd52d8..387073c627 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
diff --git a/auth_api_key/models/ir_http.py b/auth_api_key/models/ir_http.py
index d79da075c8..2a14cac38f 100644
--- a/auth_api_key/models/ir_http.py
+++ b/auth_api_key/models/ir_http.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# Copyright 2018 ACSONE SA/NV
# Copyright 2017 Akretion (http://www.akretion.com).
# @author Sébastien BEAU
diff --git a/auth_api_key/tests/test_auth_api_key.py b/auth_api_key/tests/test_auth_api_key.py
index 284a5aeba9..0e3c7d9f88 100644
--- a/auth_api_key/tests/test_auth_api_key.py
+++ b/auth_api_key/tests/test_auth_api_key.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
From 45127d53ce9664dd038c84c9e752fb4f5ba7d6a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?=
Date: Tue, 20 Nov 2018 19:22:57 +0100
Subject: [PATCH 015/107] auth_api_key: add description to model
---
auth_api_key/models/auth_api_key.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 387073c627..b302d2da5b 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -10,6 +10,7 @@
class AuthApiKey(models.TransientModel):
_name = "auth.api.key"
+ _description = "API Key Retriever"
@api.model
@tools.ormcache("api_key")
From 3d092f6bbfe379b1429d53aeb37021f5e4103483 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?=
Date: Wed, 21 Nov 2018 11:07:12 +0100
Subject: [PATCH 016/107] [CHG] auth_api_key is LGPL
---
auth_api_key/__manifest__.py | 4 ++--
auth_api_key/models/auth_api_key.py | 2 +-
auth_api_key/models/ir_http.py | 2 +-
auth_api_key/tests/test_auth_api_key.py | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index ae027c0310..896e30b8a9 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# Copyright 2018 ACSONE SA/NV
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "Auth Api Key",
"summary": """
Authenticate http requests from an API key""",
"version": "12.0.1.0.0",
- "license": "AGPL-3",
+ "license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://acsone.eu/",
"development_status": "Beta",
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index b302d2da5b..b39735f2c3 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -1,5 +1,5 @@
# Copyright 2018 ACSONE SA/NV
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo import api, models, tools, _
diff --git a/auth_api_key/models/ir_http.py b/auth_api_key/models/ir_http.py
index 2a14cac38f..1e6638a07d 100644
--- a/auth_api_key/models/ir_http.py
+++ b/auth_api_key/models/ir_http.py
@@ -1,7 +1,7 @@
# Copyright 2018 ACSONE SA/NV
# Copyright 2017 Akretion (http://www.akretion.com).
# @author Sébastien BEAU
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
import logging
diff --git a/auth_api_key/tests/test_auth_api_key.py b/auth_api_key/tests/test_auth_api_key.py
index 0e3c7d9f88..a187aed1b9 100644
--- a/auth_api_key/tests/test_auth_api_key.py
+++ b/auth_api_key/tests/test_auth_api_key.py
@@ -1,5 +1,5 @@
# Copyright 2018 ACSONE SA/NV
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo.tests.common import TransactionCase
from odoo.addons.server_environment import serv_config
from odoo.exceptions import ValidationError, AccessError
From b77aeeb9274ad3e914ec48e9eb91b8b8cfd6a0f8 Mon Sep 17 00:00:00 2001
From: Andreas Perhab <38032588+ap-wtioit@users.noreply.github.com>
Date: Fri, 30 Nov 2018 11:23:10 +0100
Subject: [PATCH 017/107] Use consteq to compare keys
Co-Authored-By: qgroulard <43472442+qgroulard@users.noreply.github.com>
---
auth_api_key/models/auth_api_key.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index b39735f2c3..1c435a09f0 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -4,6 +4,7 @@
from odoo import api, models, tools, _
from odoo.addons.server_environment import serv_config
+from odoo.tools import consteq
from odoo.exceptions import ValidationError, AccessError
@@ -22,7 +23,7 @@ def _retrieve_uid_from_api_key(self, api_key):
if section.startswith("api_key_") and serv_config.has_option(
section, "key"
):
- if api_key != serv_config.get(section, "key"):
+ if not consteq(api_key, serv_config.get(section, "key")):
continue
login_name = serv_config.get(section, "user")
From 5348741f39561c1ab85a08fd49b6a447cd38bf5d Mon Sep 17 00:00:00 2001
From: OCA-git-bot
Date: Thu, 14 Feb 2019 10:29:14 +0000
Subject: [PATCH 018/107] [UPD] README.rst
---
auth_api_key/README.rst | 16 ++++++++--------
auth_api_key/static/description/index.html | 6 +++---
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
index cbdf2d6b2d..dc5e5bc240 100644
--- a/auth_api_key/README.rst
+++ b/auth_api_key/README.rst
@@ -10,17 +10,17 @@ Auth Api Key
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
-.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
- :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
- :alt: License: AGPL-3
+.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
+ :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
+ :alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
- :target: https://github.com/OCA/server-auth/tree/10.0/auth_api_key
+ :target: https://github.com/OCA/server-auth/tree/12.0/auth_api_key
:alt: OCA/server-auth
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/server-auth-10-0/server-auth-10-0-auth_api_key
+ :target: https://translation.odoo-community.org/projects/server-auth-12-0/server-auth-12-0-auth_api_key
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
- :target: https://runbot.odoo-community.org/runbot/251/10.0
+ :target: https://runbot.odoo-community.org/runbot/251/12.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -70,7 +70,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -103,6 +103,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-This module is part of the `OCA/server-auth `_ project on GitHub.
+This module is part of the `OCA/server-auth `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
index c5d2d31987..f70369a5af 100644
--- a/auth_api_key/static/description/index.html
+++ b/auth_api_key/static/description/index.html
@@ -367,7 +367,7 @@
Auth Api Key
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
Authenticate http requests from an API key.
API keys are codes passed in (in the http header API-KEY) by programs calling an API in order to identify -in this case- the calling program’s user.
Take care while using this kind of mechanism since information into http headers are visible in clear. Thus, use it only to authenticate requests from known sources. For unknown sources, it is a good practice to filter out this header at proxy level.
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
-feedback.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-
This module is part of the OCA/server-auth project on GitHub.
+
This module is part of the OCA/server-auth project on GitHub.
API keys are codes passed in (in the http header API-KEY) by programs
calling an API in order to identify -in this case- the calling program’s
@@ -407,7 +412,7 @@
To apply this authentication system to your http request you must set
‘api_key’ as value for the ‘auth’ parameter of your route definition
into your controller.
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
@@ -436,15 +441,15 @@
From a026035961cfecf36f73b349f8da6a4e82c9bf3f Mon Sep 17 00:00:00 2001
From: arantxa-s73
Date: Thu, 4 Dec 2025 08:52:14 +0100
Subject: [PATCH 085/107] [IMP] auth_api_key: pre-commit auto fixes
---
auth_api_key/models/auth_api_key.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index cdbda3b93e..6130e4764c 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -1,7 +1,7 @@
# Copyright 2018 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
-from odoo import _, api, fields, models, tools
+from odoo import api, fields, models, tools
from odoo.exceptions import AccessError, ValidationError
from odoo.tools import consteq
@@ -39,11 +39,13 @@ def _retrieve_api_key(self, key):
@tools.ormcache("key")
def _retrieve_api_key_id(self, key):
if not self.env.user.has_group("base.group_system"):
- raise AccessError(_("User is not allowed"))
- for api_key in self.search([]):
+ raise AccessError(self.env._("User is not allowed"))
+ for api_key in self.search([], limit=None):
if api_key.key and consteq(key, api_key.key):
return api_key.id
- raise ValidationError(_(f"The key {key} is not allowed"))
+ raise ValidationError(
+ self.env._("The key {key} is not allowed").format(key=key)
+ )
@api.model
@tools.ormcache("key")
From d23f046a26ecf598dc798e0987789693112f38e2 Mon Sep 17 00:00:00 2001
From: arantxa-s73
Date: Thu, 4 Dec 2025 09:40:16 +0100
Subject: [PATCH 086/107] [MIG] auth_api_key: Migration to 19.0
---
auth_api_key/README.rst | 32 +++++++++++-----------
auth_api_key/__manifest__.py | 2 +-
auth_api_key/models/auth_api_key.py | 6 ++--
auth_api_key/static/description/index.html | 6 ++--
auth_api_key/tests/test_auth_api_key.py | 19 ++++++++++---
5 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
index 8b00287c04..53c202a1d8 100644
--- a/auth_api_key/README.rst
+++ b/auth_api_key/README.rst
@@ -21,13 +21,13 @@ Auth Api Key
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
- :target: https://github.com/OCA/server-auth/tree/18.0/auth_api_key
+ :target: https://github.com/OCA/server-auth/tree/19.0/auth_api_key
:alt: OCA/server-auth
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/server-auth-18-0/server-auth-18-0-auth_api_key
+ :target: https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_api_key
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=18.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=19.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -49,11 +49,11 @@ Odoo allows users to authenticate ``XMLRPC/JSONRPC`` calls using their
API key instead of a password by native API keys (``res.users.apikey``).
However, ``auth_api_key`` has some special features of its own such as:
-- API keys remain usable even when the user is inactive, if enabled via
- settings (e.g., for system users in a shopinvader case).
-- Supports dual authentication via Basic Auth and API_KEY in separate
- HTTP headers.
-- Admins can manage API keys for all users
+- API keys remain usable even when the user is inactive, if enabled via
+ settings (e.g., for system users in a shopinvader case).
+- Supports dual authentication via Basic Auth and API_KEY in separate
+ HTTP headers.
+- Admins can manage API keys for all users
Given these advantages, particularly in use case like system user
authentication, we have decided to keep the ``auth_api_key`` module
@@ -94,7 +94,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -109,12 +109,12 @@ Authors
Contributors
------------
-- Denis Robinet
-- Laurent Mignon
-- Quentin Groulard
-- Sébastien Beau
-- Chafique Delli
-- Thien Vo Hong
+- Denis Robinet
+- Laurent Mignon
+- Quentin Groulard
+- Sébastien Beau
+- Chafique Delli
+- Thien Vo Hong
Other credits
-------------
@@ -135,6 +135,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-This module is part of the `OCA/server-auth `_ project on GitHub.
+This module is part of the `OCA/server-auth `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index 3138bcde2d..ce16e39fb5 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -5,7 +5,7 @@
"name": "Auth Api Key",
"summary": """
Authenticate http requests from an API key""",
- "version": "18.0.1.0.1",
+ "version": "19.0.1.0.1",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-auth",
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 6130e4764c..8124566bad 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -29,7 +29,7 @@ class AuthApiKey(models.Model):
compute="_compute_active", readonly=False, store=True, default=True
)
- _sql_constraints = [("name_uniq", "unique(name)", "Api Key name must be unique.")]
+ _name_uniq = models.Constraint("unique(name)", "Api Key name must be unique.")
@api.model
def _retrieve_api_key(self, key):
@@ -43,9 +43,7 @@ def _retrieve_api_key_id(self, key):
for api_key in self.search([], limit=None):
if api_key.key and consteq(key, api_key.key):
return api_key.id
- raise ValidationError(
- self.env._("The key {key} is not allowed").format(key=key)
- )
+ raise ValidationError(self.env._("The key '%s' is not allowed", key))
@api.model
@tools.ormcache("key")
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
index 251ed87f41..30259a226f 100644
--- a/auth_api_key/static/description/index.html
+++ b/auth_api_key/static/description/index.html
@@ -374,7 +374,7 @@
API keys are codes passed in (in the http header API-KEY) by programs
calling an API in order to identify -in this case- the calling program’s
@@ -437,7 +437,7 @@
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-
This module is part of the OCA/server-auth project on GitHub.
+
This module is part of the OCA/server-auth project on GitHub.
diff --git a/auth_api_key/tests/test_auth_api_key.py b/auth_api_key/tests/test_auth_api_key.py
index 7908c42eb7..5fe6b9a187 100644
--- a/auth_api_key/tests/test_auth_api_key.py
+++ b/auth_api_key/tests/test_auth_api_key.py
@@ -9,13 +9,24 @@ class TestAuthApiKey(TransactionCase):
def setUpClass(cls, *args, **kwargs):
super().setUpClass(*args, **kwargs)
cls.AuthApiKey = cls.env["auth.api.key"]
- cls.demo_user = cls.env.ref("base.user_demo")
+ cls.partner_demo = cls.env["res.partner"].create(
+ {
+ "name": "Demo Partner",
+ }
+ )
+ cls.demo_user = cls.env["res.users"].create(
+ {
+ "partner_id": cls.partner_demo.id,
+ "login": "demotest",
+ "password": "demotest",
+ }
+ )
cls.api_key_good = cls.AuthApiKey.create(
{"name": "good", "user_id": cls.demo_user.id, "key": "api_key"}
)
def test_lookup_key_from_db(self):
- demo_user = self.env.ref("base.user_demo")
+ demo_user = self.demo_user
self.assertEqual(
self.env["auth.api.key"]._retrieve_uid_from_api_key("api_key"), demo_user.id
)
@@ -46,7 +57,7 @@ def test_cache_invalidation(self):
def test_user_archived_unarchived_with_option_on(self):
self.env.company.archived_user_disable_auth_api_key = True
- demo_user = self.env.ref("base.user_demo")
+ demo_user = self.demo_user
self.assertEqual(
self.env["auth.api.key"]._retrieve_uid_from_api_key("api_key"), demo_user.id
)
@@ -60,7 +71,7 @@ def test_user_archived_unarchived_with_option_on(self):
def test_user_archived_unarchived_with_option_off(self):
self.env.company.archived_user_disable_auth_api_key = False
- demo_user = self.env.ref("base.user_demo")
+ demo_user = self.demo_user
self.assertEqual(
self.env["auth.api.key"]._retrieve_uid_from_api_key("api_key"), demo_user.id
)
From 4ad2acba7f79374f80950d3d65b15d49b1c4f683 Mon Sep 17 00:00:00 2001
From: oca-ci
Date: Tue, 21 Apr 2026 08:35:50 +0000
Subject: [PATCH 087/107] [UPD] Update auth_api_key.pot
---
auth_api_key/i18n/auth_api_key.pot | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/auth_api_key/i18n/auth_api_key.pot b/auth_api_key/i18n/auth_api_key.pot
index 9b7fa0fcbc..bf39424815 100644
--- a/auth_api_key/i18n/auth_api_key.pot
+++ b/auth_api_key/i18n/auth_api_key.pot
@@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
-"Project-Id-Version: Odoo Server 18.0\n"
+"Project-Id-Version: Odoo Server 19.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -72,6 +72,9 @@ msgstr ""
#. module: auth_api_key
#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_ir_http__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_res_company__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_res_config_settings__display_name
msgid "Display Name"
msgstr ""
@@ -82,6 +85,9 @@ msgstr ""
#. module: auth_api_key
#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__id
+#: model:ir.model.fields,field_description:auth_api_key.field_ir_http__id
+#: model:ir.model.fields,field_description:auth_api_key.field_res_company__id
+#: model:ir.model.fields,field_description:auth_api_key.field_res_config_settings__id
msgid "ID"
msgstr ""
@@ -121,6 +127,12 @@ msgid ""
" obtained from the server environment configuration."
msgstr ""
+#. module: auth_api_key
+#. odoo-python
+#: code:addons/auth_api_key/models/auth_api_key.py:0
+msgid "The key '%s' is not allowed"
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__user_id
msgid ""
From 87a0737b901514dff20f4f3a8c1e87ec6efba849 Mon Sep 17 00:00:00 2001
From: OCA-git-bot
Date: Tue, 21 Apr 2026 08:38:21 +0000
Subject: [PATCH 088/107] [BOT] post-merge updates
---
auth_api_key/README.rst | 24 +++++++++++-----------
auth_api_key/static/description/index.html | 2 +-
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
index 53c202a1d8..d7a48e4d21 100644
--- a/auth_api_key/README.rst
+++ b/auth_api_key/README.rst
@@ -11,7 +11,7 @@ Auth Api Key
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:78e3946b0dbb81bb6fbf6c434aaf5214faec00449a765c2f41e321b65024ba05
+ !! source digest: sha256:66a1fbebbd39def7609edaa4fea590c1828066ce3586ad30ba1c122ca3a106ec
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
@@ -49,11 +49,11 @@ Odoo allows users to authenticate ``XMLRPC/JSONRPC`` calls using their
API key instead of a password by native API keys (``res.users.apikey``).
However, ``auth_api_key`` has some special features of its own such as:
-- API keys remain usable even when the user is inactive, if enabled via
- settings (e.g., for system users in a shopinvader case).
-- Supports dual authentication via Basic Auth and API_KEY in separate
- HTTP headers.
-- Admins can manage API keys for all users
+- API keys remain usable even when the user is inactive, if enabled via
+ settings (e.g., for system users in a shopinvader case).
+- Supports dual authentication via Basic Auth and API_KEY in separate
+ HTTP headers.
+- Admins can manage API keys for all users
Given these advantages, particularly in use case like system user
authentication, we have decided to keep the ``auth_api_key`` module
@@ -109,12 +109,12 @@ Authors
Contributors
------------
-- Denis Robinet
-- Laurent Mignon
-- Quentin Groulard
-- Sébastien Beau
-- Chafique Delli
-- Thien Vo Hong
+- Denis Robinet
+- Laurent Mignon
+- Quentin Groulard
+- Sébastien Beau
+- Chafique Delli
+- Thien Vo Hong
Other credits
-------------
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
index 30259a226f..658f628557 100644
--- a/auth_api_key/static/description/index.html
+++ b/auth_api_key/static/description/index.html
@@ -372,7 +372,7 @@
Auth Api Key
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! source digest: sha256:78e3946b0dbb81bb6fbf6c434aaf5214faec00449a765c2f41e321b65024ba05
+!! source digest: sha256:66a1fbebbd39def7609edaa4fea590c1828066ce3586ad30ba1c122ca3a106ec
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
Authenticate http requests from an API key.
From 86a6a97df0dfe983203fa3b92ace6a75fdc60a46 Mon Sep 17 00:00:00 2001
From: Ryoko Tsuda
Date: Wed, 22 Apr 2026 03:39:28 +0000
Subject: [PATCH 089/107] Added translation using Weblate (Japanese)
---
auth_api_key/i18n/ja.po | 153 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 153 insertions(+)
create mode 100644 auth_api_key/i18n/ja.po
diff --git a/auth_api_key/i18n/ja.po b/auth_api_key/i18n/ja.po
new file mode 100644
index 0000000000..6e71939d21
--- /dev/null
+++ b/auth_api_key/i18n/ja.po
@@ -0,0 +1,153 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * auth_api_key
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Odoo Server 19.0\n"
+"Report-Msgid-Bugs-To: \n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"Language: ja\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: nplurals=1; plural=0;\n"
+
+#. module: auth_api_key
+#: model:ir.model,name:auth_api_key.model_auth_api_key
+msgid "API Key"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__active
+msgid "Active"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.constraint,message:auth_api_key.constraint_auth_api_key_name_uniq
+msgid "Api Key name must be unique."
+msgstr ""
+
+#. module: auth_api_key
+#: model_terms:ir.ui.view,arch_db:auth_api_key.auth_api_key_form_view
+msgid "Archived"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.actions.act_window,name:auth_api_key.auth_api_key_act_window
+#: model:ir.ui.menu,name:auth_api_key.auth_api_key_menu
+msgid "Auth Api Key"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model,name:auth_api_key.model_res_company
+msgid "Companies"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model,name:auth_api_key.model_res_config_settings
+msgid "Config Settings"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__create_uid
+msgid "Created by"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__create_date
+msgid "Created on"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_res_company__archived_user_disable_auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_res_config_settings__archived_user_disable_auth_api_key
+msgid "Disable API key for archived user"
+msgstr ""
+
+#. module: auth_api_key
+#: model_terms:ir.ui.view,arch_db:auth_api_key.res_config_settings_view_form
+msgid "Disable API key when archiving user"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_ir_http__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_res_company__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_res_config_settings__display_name
+msgid "Display Name"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model,name:auth_api_key.model_ir_http
+msgid "HTTP Routing"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__id
+#: model:ir.model.fields,field_description:auth_api_key.field_ir_http__id
+#: model:ir.model.fields,field_description:auth_api_key.field_res_company__id
+#: model:ir.model.fields,field_description:auth_api_key.field_res_config_settings__id
+msgid "ID"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,help:auth_api_key.field_res_company__archived_user_disable_auth_api_key
+#: model:ir.model.fields,help:auth_api_key.field_res_config_settings__archived_user_disable_auth_api_key
+msgid ""
+"If checked, when a user is archived/unactivated the same change is "
+"propagated to his related api key. It is not retroactive (nothing is done "
+"when enabling/disabling this option)."
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__key
+msgid "Key"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__write_uid
+msgid "Last Updated by"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__write_date
+msgid "Last Updated on"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__name
+msgid "Name"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__key
+msgid ""
+"The API key. Enter a dummy value in this field if it is\n"
+" obtained from the server environment configuration."
+msgstr ""
+
+#. module: auth_api_key
+#. odoo-python
+#: code:addons/auth_api_key/models/auth_api_key.py:0
+msgid "The key '%s' is not allowed"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__user_id
+msgid ""
+"The user used to process the requests authenticated by\n"
+" the api key"
+msgstr ""
+
+#. module: auth_api_key
+#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__user_id
+msgid "User"
+msgstr ""
+
+#. module: auth_api_key
+#. odoo-python
+#: code:addons/auth_api_key/models/auth_api_key.py:0
+msgid "User is not allowed"
+msgstr ""
From e632c65fb75e5800054f513f09545ec48ce8196b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?=
Date: Wed, 20 May 2026 16:33:16 -0300
Subject: [PATCH 090/107] [IMP] auth_api_key: add tests for controllers
---
auth_api_key/tests/__init__.py | 1 +
auth_api_key/tests/test_controllers.py | 47 ++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
create mode 100644 auth_api_key/tests/test_controllers.py
diff --git a/auth_api_key/tests/__init__.py b/auth_api_key/tests/__init__.py
index 56e3e32a3a..308b13b596 100644
--- a/auth_api_key/tests/__init__.py
+++ b/auth_api_key/tests/__init__.py
@@ -1 +1,2 @@
from . import test_auth_api_key
+from . import test_controllers
diff --git a/auth_api_key/tests/test_controllers.py b/auth_api_key/tests/test_controllers.py
new file mode 100644
index 0000000000..99cecf1d8e
--- /dev/null
+++ b/auth_api_key/tests/test_controllers.py
@@ -0,0 +1,47 @@
+# Copyright 2026 Camptocamp SA (https://www.camptocamp.com).
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+
+import json
+
+from odoo.http import Controller, route
+from odoo.tests import HttpCase, new_test_user
+from odoo.tools import mute_logger
+
+
+class TestControllers(HttpCase):
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ cls.AuthApiKey = cls.env["auth.api.key"]
+ cls.test_user = new_test_user(
+ cls.env,
+ name="Test User",
+ login="test",
+ password="test",
+ email="test@test.com",
+ group_ids=[cls.env.ref("base.group_user").id],
+ company_id=cls.env.company.id,
+ )
+ cls.api_key = cls.AuthApiKey.create(
+ {"name": "good", "user_id": cls.test_user.id, "key": "api_key"}
+ )
+
+ class DummyController(Controller):
+ @route("/web/auth-api-key", type="http", auth="api_key", sitemap=False)
+ def auth_api_key(self, **params):
+ return json.dumps({"name": self.env.user.name})
+
+ cls.env.registry.clear_cache("routing")
+ cls.addClassCleanup(cls.env.registry.clear_cache, "routing")
+
+ def test_auth_api_key_ok(self):
+ res = self.url_open("/web/auth-api-key", headers={"API-KEY": self.api_key.key})
+ self.assertEqual(res.status_code, 200)
+ self.assertEqual(res.json(), {"name": self.test_user.name})
+
+ @mute_logger("odoo.addons.base.models.ir_http")
+ def test_auth_api_key_wrong(self):
+ with self.assertLogs("odoo.http") as cm:
+ res = self.url_open("/web/auth-api-key", headers={"API-KEY": "wrong"})
+ self.assertEqual(res.status_code, 403)
+ self.assertIn("Access Denied", cm.output[0])
From 01a1349fcffda208d163c6369b123d3aaebedf3e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?=
Date: Wed, 20 May 2026 16:54:27 -0300
Subject: [PATCH 091/107] [FIX] auth_api_key: report allowed header in cors
OPTIONS
---
auth_api_key/__init__.py | 1 +
auth_api_key/__manifest__.py | 1 +
auth_api_key/hooks.py | 52 ++++++++++++++++++++++++++
auth_api_key/tests/test_controllers.py | 10 +++++
4 files changed, 64 insertions(+)
create mode 100644 auth_api_key/hooks.py
diff --git a/auth_api_key/__init__.py b/auth_api_key/__init__.py
index 0650744f6b..5bf67492bc 100644
--- a/auth_api_key/__init__.py
+++ b/auth_api_key/__init__.py
@@ -1 +1,2 @@
from . import models
+from .hooks import post_load_hook
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index ce16e39fb5..8cdfac8ae5 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -11,6 +11,7 @@
"website": "https://github.com/OCA/server-auth",
"development_status": "Production/Stable",
"depends": ["base_setup"],
+ "post_load": "post_load_hook",
"data": [
"security/ir.model.access.csv",
"views/auth_api_key.xml",
diff --git a/auth_api_key/hooks.py b/auth_api_key/hooks.py
new file mode 100644
index 0000000000..6fb64d994d
--- /dev/null
+++ b/auth_api_key/hooks.py
@@ -0,0 +1,52 @@
+# Copyright 2026 Camptocamp SA (https://www.camptocamp.com).
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+
+from werkzeug.exceptions import HTTPException
+from werkzeug.wrappers import Response
+
+from odoo.http import Dispatcher
+
+
+def patch_dispatcher_pre_dispatch():
+ """Patch odoo.http.Dispatcher's pre_dispatch method.
+
+ For routes with cors enabled, Odoo will add a handler for the OPTIONS method,
+ which will raise an abort HTTPException with a 204 response describing the allowed
+ methods and headers in the Access-Control-* respnose headers.
+
+ For routes with api_key authentication, we must inform the client that the
+ API-KEY header is allowed.
+ """
+ original_pre_dispatch = Dispatcher.pre_dispatch
+
+ def pre_dispatch(self, rule, args):
+ get_header = self.request.future_response.headers.get
+ set_header = self.request.future_response.headers.set
+ routing = rule.endpoint.routing
+ if (
+ routing.get("cors")
+ and routing.get("auth") == "api_key"
+ and self.request.httprequest.method == "OPTIONS"
+ ):
+ try:
+ return original_pre_dispatch(self, rule, args)
+ except HTTPException as e:
+ if (
+ isinstance(e.response, Response)
+ and e.response.status_code == 204
+ and get_header("Access-Control-Allow-Headers")
+ ):
+ set_header(
+ "Access-Control-Allow-Headers",
+ f"{get_header('Access-Control-Allow-Headers')}, API-Key",
+ )
+ raise
+ else:
+ return original_pre_dispatch(self, rule, args)
+
+ Dispatcher.pre_dispatch = pre_dispatch
+ Dispatcher.pre_dispatch._original_method = original_pre_dispatch
+
+
+def post_load_hook():
+ patch_dispatcher_pre_dispatch()
diff --git a/auth_api_key/tests/test_controllers.py b/auth_api_key/tests/test_controllers.py
index 99cecf1d8e..b965d1b49e 100644
--- a/auth_api_key/tests/test_controllers.py
+++ b/auth_api_key/tests/test_controllers.py
@@ -31,6 +31,10 @@ class DummyController(Controller):
def auth_api_key(self, **params):
return json.dumps({"name": self.env.user.name})
+ @route("/web/auth-api-key-cors", type="http", auth="api_key", cors="*")
+ def auth_api_key_cors(self, **params):
+ return json.dumps({"name": self.env.user.name})
+
cls.env.registry.clear_cache("routing")
cls.addClassCleanup(cls.env.registry.clear_cache, "routing")
@@ -45,3 +49,9 @@ def test_auth_api_key_wrong(self):
res = self.url_open("/web/auth-api-key", headers={"API-KEY": "wrong"})
self.assertEqual(res.status_code, 403)
self.assertIn("Access Denied", cm.output[0])
+
+ def test_auth_api_key_cors_options(self):
+ res = self.url_open("/web/auth-api-key-cors", method="OPTIONS")
+ self.assertEqual(res.status_code, 204)
+ self.assertEqual(res.headers["Access-Control-Allow-Origin"], "*")
+ self.assertIn("API-Key", res.headers["Access-Control-Allow-Headers"])
From 8d9eec91d840e69c7e4bee0b9aea2cf4100d3c8e Mon Sep 17 00:00:00 2001
From: OCA-git-bot
Date: Tue, 26 May 2026 13:40:09 +0000
Subject: [PATCH 092/107] [BOT] post-merge updates
---
auth_api_key/README.rst | 2 +-
auth_api_key/__manifest__.py | 2 +-
auth_api_key/static/description/index.html | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
index d7a48e4d21..a9a06edb95 100644
--- a/auth_api_key/README.rst
+++ b/auth_api_key/README.rst
@@ -11,7 +11,7 @@ Auth Api Key
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:66a1fbebbd39def7609edaa4fea590c1828066ce3586ad30ba1c122ca3a106ec
+ !! source digest: sha256:0f3e857bf22cd42db4da93a05993023a71d0839e378d459b33ecd6063b9f6f51
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index 8cdfac8ae5..afef0adc4b 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -5,7 +5,7 @@
"name": "Auth Api Key",
"summary": """
Authenticate http requests from an API key""",
- "version": "19.0.1.0.1",
+ "version": "19.0.1.0.2",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-auth",
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
index 658f628557..9c70fd4298 100644
--- a/auth_api_key/static/description/index.html
+++ b/auth_api_key/static/description/index.html
@@ -372,7 +372,7 @@
Auth Api Key
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! source digest: sha256:66a1fbebbd39def7609edaa4fea590c1828066ce3586ad30ba1c122ca3a106ec
+!! source digest: sha256:0f3e857bf22cd42db4da93a05993023a71d0839e378d459b33ecd6063b9f6f51
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
Authenticate http requests from an API key.
From 1ba1c9f74ee144bf6e9edc8575515e640393533f Mon Sep 17 00:00:00 2001
From: Maksym Yankin
Date: Thu, 11 Jun 2026 15:40:24 +0300
Subject: [PATCH 093/107] [19.0][IMP] auth_api_key: neutralize API keys
---
auth_api_key/README.rst | 2 ++
auth_api_key/data/neutralize.sql | 3 +++
auth_api_key/models/auth_api_key.py | 9 ++++++--
auth_api_key/readme/CONFIGURE.md | 2 ++
auth_api_key/static/description/index.html | 1 +
auth_api_key/tests/__init__.py | 1 +
auth_api_key/tests/test_auth_api_key.py | 8 +++++++
auth_api_key/tests/test_neutralize.py | 25 ++++++++++++++++++++++
8 files changed, 49 insertions(+), 2 deletions(-)
create mode 100644 auth_api_key/data/neutralize.sql
create mode 100644 auth_api_key/tests/test_neutralize.py
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
index a9a06edb95..627ac8b97a 100644
--- a/auth_api_key/README.rst
+++ b/auth_api_key/README.rst
@@ -70,6 +70,8 @@ The api key menu is available into Settings > Technical in debug mode.
By default, when you create an API key, the key is saved into the
database.
+When a database is neutralized, stored API key values are cleared.
+
If you want to manage them via serve environment settings use
auth_api_key_server_env.
diff --git a/auth_api_key/data/neutralize.sql b/auth_api_key/data/neutralize.sql
new file mode 100644
index 0000000000..d23b229ef7
--- /dev/null
+++ b/auth_api_key/data/neutralize.sql
@@ -0,0 +1,3 @@
+-- remove API keys
+UPDATE auth_api_key
+ SET key = NULL;
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 8124566bad..ee8564a6f1 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -12,7 +12,6 @@ class AuthApiKey(models.Model):
name = fields.Char(required=True)
key = fields.Char(
- required=True,
help="""The API key. Enter a dummy value in this field if it is
obtained from the server environment configuration.""",
)
@@ -31,6 +30,12 @@ class AuthApiKey(models.Model):
_name_uniq = models.Constraint("unique(name)", "Api Key name must be unique.")
+ @api.constrains("key")
+ def _check_key_required(self):
+ for api_key in self:
+ if not api_key.key:
+ raise ValidationError(self.env._("The API key is required."))
+
@api.model
def _retrieve_api_key(self, key):
return self.browse(self._retrieve_api_key_id(key))
@@ -40,7 +45,7 @@ def _retrieve_api_key(self, key):
def _retrieve_api_key_id(self, key):
if not self.env.user.has_group("base.group_system"):
raise AccessError(self.env._("User is not allowed"))
- for api_key in self.search([], limit=None):
+ for api_key in self.search([("key", "!=", False)], limit=None):
if api_key.key and consteq(key, api_key.key):
return api_key.id
raise ValidationError(self.env._("The key '%s' is not allowed", key))
diff --git a/auth_api_key/readme/CONFIGURE.md b/auth_api_key/readme/CONFIGURE.md
index f791dd13ab..d333318925 100644
--- a/auth_api_key/readme/CONFIGURE.md
+++ b/auth_api_key/readme/CONFIGURE.md
@@ -2,5 +2,7 @@ The api key menu is available into Settings \> Technical in debug mode.
By default, when you create an API key, the key is saved into the
database.
+When a database is neutralized, stored API key values are cleared.
+
If you want to manage them via serve environment settings use
auth_api_key_server_env.
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
index 9c70fd4298..0a9612b8a9 100644
--- a/auth_api_key/static/description/index.html
+++ b/auth_api_key/static/description/index.html
@@ -416,6 +416,7 @@
The api key menu is available into Settings > Technical in debug mode.
By default, when you create an API key, the key is saved into the
database.
+
When a database is neutralized, stored API key values are cleared.
If you want to manage them via serve environment settings use
auth_api_key_server_env.
diff --git a/auth_api_key/tests/__init__.py b/auth_api_key/tests/__init__.py
index 308b13b596..7cb6186a03 100644
--- a/auth_api_key/tests/__init__.py
+++ b/auth_api_key/tests/__init__.py
@@ -1,2 +1,3 @@
from . import test_auth_api_key
from . import test_controllers
+from . import test_neutralize
diff --git a/auth_api_key/tests/test_auth_api_key.py b/auth_api_key/tests/test_auth_api_key.py
index 5fe6b9a187..d78e299bff 100644
--- a/auth_api_key/tests/test_auth_api_key.py
+++ b/auth_api_key/tests/test_auth_api_key.py
@@ -35,6 +35,14 @@ def test_wrong_key(self):
with self.assertRaises(ValidationError), self.env.cr.savepoint():
self.env["auth.api.key"]._retrieve_uid_from_api_key("api_wrong_key")
+ def test_empty_key_is_rejected(self):
+ with self.assertRaises(ValidationError), self.env.cr.savepoint():
+ self.AuthApiKey.create(
+ {"name": "empty", "user_id": self.demo_user.id, "key": ""}
+ )
+ with self.assertRaises(ValidationError), self.env.cr.savepoint():
+ self.api_key_good.key = False
+
def test_user_not_allowed(self):
# only system users can check for key
with self.assertRaises(AccessError), self.env.cr.savepoint():
diff --git a/auth_api_key/tests/test_neutralize.py b/auth_api_key/tests/test_neutralize.py
new file mode 100644
index 0000000000..4b5d16828b
--- /dev/null
+++ b/auth_api_key/tests/test_neutralize.py
@@ -0,0 +1,25 @@
+# Copyright 2026 Camptocamp SA
+# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
+
+from odoo.modules import neutralize
+from odoo.tests import tagged
+from odoo.tests.common import TransactionCase
+
+
+@tagged("post_install", "-at_install", "neutralize")
+class TestAuthApiKeyNeutralize(TransactionCase):
+ def test_neutralize_removes_api_key_values(self):
+ """Test database neutralization clears stored API key secrets."""
+ api_key = self.env["auth.api.key"].create(
+ {
+ "name": "neutralize",
+ "user_id": self.env.ref("base.user_admin").id,
+ "key": "secret-key",
+ }
+ )
+
+ queries = neutralize.get_neutralization_queries(["auth_api_key"])
+ for query in queries:
+ self.cr.execute(query)
+ api_key.invalidate_recordset(["key"])
+ self.assertFalse(api_key.key)
From 4b110469e55d26d7e76226b2dc5f5add73881ee4 Mon Sep 17 00:00:00 2001
From: oca-ci
Date: Wed, 15 Jul 2026 12:22:59 +0000
Subject: [PATCH 094/107] [UPD] Update auth_api_key.pot
---
auth_api_key/i18n/auth_api_key.pot | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/auth_api_key/i18n/auth_api_key.pot b/auth_api_key/i18n/auth_api_key.pot
index bf39424815..910901518c 100644
--- a/auth_api_key/i18n/auth_api_key.pot
+++ b/auth_api_key/i18n/auth_api_key.pot
@@ -120,6 +120,12 @@ msgstr ""
msgid "Name"
msgstr ""
+#. module: auth_api_key
+#. odoo-python
+#: code:addons/auth_api_key/models/auth_api_key.py:0
+msgid "The API key is required."
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__key
msgid ""
From a21f5ac3edb474915b0d6b281d1ece31580d1f0b Mon Sep 17 00:00:00 2001
From: OCA-git-bot
Date: Wed, 15 Jul 2026 12:25:22 +0000
Subject: [PATCH 095/107] [BOT] post-merge updates
---
auth_api_key/README.rst | 2 +-
auth_api_key/__manifest__.py | 2 +-
auth_api_key/static/description/index.html | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
index 627ac8b97a..0b185c4574 100644
--- a/auth_api_key/README.rst
+++ b/auth_api_key/README.rst
@@ -11,7 +11,7 @@ Auth Api Key
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:0f3e857bf22cd42db4da93a05993023a71d0839e378d459b33ecd6063b9f6f51
+ !! source digest: sha256:13e40ab685d9417f6461852e3c3c37fec5967c3a7a956fdb54b3fcc5f1b42115
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index afef0adc4b..856447f9dc 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -5,7 +5,7 @@
"name": "Auth Api Key",
"summary": """
Authenticate http requests from an API key""",
- "version": "19.0.1.0.2",
+ "version": "19.0.1.0.3",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-auth",
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
index 0a9612b8a9..0aec51591d 100644
--- a/auth_api_key/static/description/index.html
+++ b/auth_api_key/static/description/index.html
@@ -372,7 +372,7 @@
Auth Api Key
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! source digest: sha256:0f3e857bf22cd42db4da93a05993023a71d0839e378d459b33ecd6063b9f6f51
+!! source digest: sha256:13e40ab685d9417f6461852e3c3c37fec5967c3a7a956fdb54b3fcc5f1b42115
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
Authenticate http requests from an API key.
From c0c91be26b99daf27880a3f7cc057104d5c933b3 Mon Sep 17 00:00:00 2001
From: Weblate
Date: Wed, 15 Jul 2026 12:25:30 +0000
Subject: [PATCH 096/107] Update translation files
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.
Translation: server-auth-19.0/server-auth-19.0-auth_api_key
Translate-URL: https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_api_key/
---
auth_api_key/i18n/it.po | 22 ++++++++++++++++++++--
auth_api_key/i18n/ja.po | 6 ++++++
auth_api_key/i18n/zh_CN.po | 18 ++++++++++++++++++
3 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/auth_api_key/i18n/it.po b/auth_api_key/i18n/it.po
index dba473c4da..20b0a517c1 100644
--- a/auth_api_key/i18n/it.po
+++ b/auth_api_key/i18n/it.po
@@ -75,6 +75,9 @@ msgstr "Disabilita la chiave API quando si archivia un utente"
#. module: auth_api_key
#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_ir_http__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_res_company__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_res_config_settings__display_name
msgid "Display Name"
msgstr "Nome visualizzato"
@@ -85,6 +88,9 @@ msgstr "Instradamento HTTP"
#. module: auth_api_key
#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__id
+#: model:ir.model.fields,field_description:auth_api_key.field_ir_http__id
+#: model:ir.model.fields,field_description:auth_api_key.field_res_company__id
+#: model:ir.model.fields,field_description:auth_api_key.field_res_config_settings__id
msgid "ID"
msgstr "ID"
@@ -97,8 +103,8 @@ msgid ""
"when enabling/disabling this option)."
msgstr ""
"Se selezionata, quando un utente viene archiviato/disattivato, la stessa "
-"modifica viene propagata alla sua chiave API correlata. Non è retroattivo ("
-"non viene fatto nulla quando si abilita/disabilita questa opzione)."
+"modifica viene propagata alla sua chiave API correlata. Non è retroattivo "
+"(non viene fatto nulla quando si abilita/disabilita questa opzione)."
#. module: auth_api_key
#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__key
@@ -120,6 +126,12 @@ msgstr "Ultimo aggiornamento il"
msgid "Name"
msgstr "Nome"
+#. module: auth_api_key
+#. odoo-python
+#: code:addons/auth_api_key/models/auth_api_key.py:0
+msgid "The API key is required."
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__key
msgid ""
@@ -129,6 +141,12 @@ msgstr ""
"Chiave API. Se viene acquisita dalla configurazione\n"
" ambiente del server, inserire nel campo un valore fittizio."
+#. module: auth_api_key
+#. odoo-python
+#: code:addons/auth_api_key/models/auth_api_key.py:0
+msgid "The key '%s' is not allowed"
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__user_id
msgid ""
diff --git a/auth_api_key/i18n/ja.po b/auth_api_key/i18n/ja.po
index 6e71939d21..baf16ead11 100644
--- a/auth_api_key/i18n/ja.po
+++ b/auth_api_key/i18n/ja.po
@@ -121,6 +121,12 @@ msgstr ""
msgid "Name"
msgstr ""
+#. module: auth_api_key
+#. odoo-python
+#: code:addons/auth_api_key/models/auth_api_key.py:0
+msgid "The API key is required."
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__key
msgid ""
diff --git a/auth_api_key/i18n/zh_CN.po b/auth_api_key/i18n/zh_CN.po
index 311e21a7c7..dd912a4421 100644
--- a/auth_api_key/i18n/zh_CN.po
+++ b/auth_api_key/i18n/zh_CN.po
@@ -73,6 +73,9 @@ msgstr ""
#. module: auth_api_key
#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_ir_http__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_res_company__display_name
+#: model:ir.model.fields,field_description:auth_api_key.field_res_config_settings__display_name
msgid "Display Name"
msgstr ""
@@ -83,6 +86,9 @@ msgstr ""
#. module: auth_api_key
#: model:ir.model.fields,field_description:auth_api_key.field_auth_api_key__id
+#: model:ir.model.fields,field_description:auth_api_key.field_ir_http__id
+#: model:ir.model.fields,field_description:auth_api_key.field_res_company__id
+#: model:ir.model.fields,field_description:auth_api_key.field_res_config_settings__id
msgid "ID"
msgstr ""
@@ -115,6 +121,12 @@ msgstr ""
msgid "Name"
msgstr ""
+#. module: auth_api_key
+#. odoo-python
+#: code:addons/auth_api_key/models/auth_api_key.py:0
+msgid "The API key is required."
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__key
msgid ""
@@ -122,6 +134,12 @@ msgid ""
" obtained from the server environment configuration."
msgstr ""
+#. module: auth_api_key
+#. odoo-python
+#: code:addons/auth_api_key/models/auth_api_key.py:0
+msgid "The key '%s' is not allowed"
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__user_id
msgid ""
From 1042dceadbbb5dd7a08e2ae620f27862e1fc64fa Mon Sep 17 00:00:00 2001
From: mymage
Date: Mon, 20 Jul 2026 06:43:12 +0000
Subject: [PATCH 097/107] Translated using Weblate (Italian)
Currently translated at 100.0% (25 of 25 strings)
Translation: server-auth-19.0/server-auth-19.0-auth_api_key
Translate-URL: https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_api_key/it/
---
auth_api_key/i18n/it.po | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/auth_api_key/i18n/it.po b/auth_api_key/i18n/it.po
index 20b0a517c1..4a8682150d 100644
--- a/auth_api_key/i18n/it.po
+++ b/auth_api_key/i18n/it.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
-"PO-Revision-Date: 2024-10-13 18:06+0000\n"
+"PO-Revision-Date: 2026-07-20 08:46+0000\n"
"Last-Translator: mymage \n"
"Language-Team: none\n"
"Language: it\n"
@@ -14,7 +14,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
-"X-Generator: Weblate 5.6.2\n"
+"X-Generator: Weblate 5.15.2\n"
#. module: auth_api_key
#: model:ir.model,name:auth_api_key.model_auth_api_key
@@ -130,7 +130,7 @@ msgstr "Nome"
#. odoo-python
#: code:addons/auth_api_key/models/auth_api_key.py:0
msgid "The API key is required."
-msgstr ""
+msgstr "La chiave API è richiesta."
#. module: auth_api_key
#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__key
@@ -145,7 +145,7 @@ msgstr ""
#. odoo-python
#: code:addons/auth_api_key/models/auth_api_key.py:0
msgid "The key '%s' is not allowed"
-msgstr ""
+msgstr "Chiave '%s' non autorizzata"
#. module: auth_api_key
#: model:ir.model.fields,help:auth_api_key.field_auth_api_key__user_id
From 10d66c257ba3087a556ed3b485922fcdb313fa6b Mon Sep 17 00:00:00 2001
From: Maksym Yankin
Date: Thu, 11 Jun 2026 15:25:12 +0300
Subject: [PATCH 098/107] [IMP] auth_api_key: generate API keys automatically
---
auth_api_key/README.rst | 5 +++++
auth_api_key/models/auth_api_key.py | 25 ++++++++++++++++++++++
auth_api_key/readme/CONFIGURE.md | 5 +++++
auth_api_key/static/description/index.html | 4 ++++
auth_api_key/tests/test_auth_api_key.py | 19 ++++++++++++++++
auth_api_key/views/auth_api_key.xml | 13 ++++++++++-
6 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
index 0b185c4574..a673737556 100644
--- a/auth_api_key/README.rst
+++ b/auth_api_key/README.rst
@@ -70,6 +70,11 @@ The api key menu is available into Settings > Technical in debug mode.
By default, when you create an API key, the key is saved into the
database.
+When you create an API key, a random key is generated automatically. You
+can replace it manually, or use the Generate Random Token button if an
+existing record has no key. The key field is masked by default, and the
+password widget provides a button to reveal the value when needed.
+
When a database is neutralized, stored API key values are cleared.
If you want to manage them via serve environment settings use
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index ee8564a6f1..63eef6b735 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -1,6 +1,8 @@
# Copyright 2018 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
+import secrets
+
from odoo import api, fields, models, tools
from odoo.exceptions import AccessError, ValidationError
from odoo.tools import consteq
@@ -12,6 +14,7 @@ class AuthApiKey(models.Model):
name = fields.Char(required=True)
key = fields.Char(
+ default=lambda self: self._generate_random_key_value(),
help="""The API key. Enter a dummy value in this field if it is
obtained from the server environment configuration.""",
)
@@ -36,6 +39,28 @@ def _check_key_required(self):
if not api_key.key:
raise ValidationError(self.env._("The API key is required."))
+ @api.model
+ def _generate_random_key_value(self):
+ """Return a random API key value.
+
+ The token is generated by the Odoo server instance so XML data and the
+ UI button can create a secret without storing any default value in the
+ module sources.
+ """
+ return secrets.token_urlsafe(32)
+
+ def generate_random_key(self, api_key_ids=None):
+ """Generate a key for records that do not have one yet.
+
+ :param list api_key_ids: optional record IDs, mainly used by XML data
+ function calls where the method is invoked on the model.
+ :return: True when the operation completed.
+ """
+ api_keys = self.browse(api_key_ids) if api_key_ids else self
+ for api_key in api_keys.filtered(lambda record: not record.key):
+ api_key.key = api_key._generate_random_key_value()
+ return True
+
@api.model
def _retrieve_api_key(self, key):
return self.browse(self._retrieve_api_key_id(key))
diff --git a/auth_api_key/readme/CONFIGURE.md b/auth_api_key/readme/CONFIGURE.md
index d333318925..12f823bb97 100644
--- a/auth_api_key/readme/CONFIGURE.md
+++ b/auth_api_key/readme/CONFIGURE.md
@@ -2,6 +2,11 @@ The api key menu is available into Settings \> Technical in debug mode.
By default, when you create an API key, the key is saved into the
database.
+When you create an API key, a random key is generated automatically. You
+can replace it manually, or use the Generate Random Token button if an
+existing record has no key. The key field is masked by default, and the
+password widget provides a button to reveal the value when needed.
+
When a database is neutralized, stored API key values are cleared.
If you want to manage them via serve environment settings use
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
index 0aec51591d..8cbfb4da83 100644
--- a/auth_api_key/static/description/index.html
+++ b/auth_api_key/static/description/index.html
@@ -416,6 +416,10 @@
The api key menu is available into Settings > Technical in debug mode.
By default, when you create an API key, the key is saved into the
database.
+
When you create an API key, a random key is generated automatically. You
+can replace it manually, or use the Generate Random Token button if an
+existing record has no key. The key field is masked by default, and the
+password widget provides a button to reveal the value when needed.
When a database is neutralized, stored API key values are cleared.
If you want to manage them via serve environment settings use
auth_api_key_server_env.
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! source digest: sha256:13e40ab685d9417f6461852e3c3c37fec5967c3a7a956fdb54b3fcc5f1b42115
+!! source digest: sha256:e7679893d3301998264999e637352ed54ac21f411be14f01b7f8b2ab102b3b50
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
Authenticate http requests from an API key.
From 48f32efba6eb31ab3cfeb330492bf1949cf17ddf Mon Sep 17 00:00:00 2001
From: Weblate
Date: Thu, 23 Jul 2026 14:19:38 +0000
Subject: [PATCH 101/107] Update translation files
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.
Translation: server-auth-19.0/server-auth-19.0-auth_api_key
Translate-URL: https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_api_key/
---
auth_api_key/i18n/it.po | 5 +++++
auth_api_key/i18n/ja.po | 5 +++++
auth_api_key/i18n/zh_CN.po | 5 +++++
3 files changed, 15 insertions(+)
diff --git a/auth_api_key/i18n/it.po b/auth_api_key/i18n/it.po
index 4a8682150d..1798529e51 100644
--- a/auth_api_key/i18n/it.po
+++ b/auth_api_key/i18n/it.po
@@ -81,6 +81,11 @@ msgstr "Disabilita la chiave API quando si archivia un utente"
msgid "Display Name"
msgstr "Nome visualizzato"
+#. module: auth_api_key
+#: model_terms:ir.ui.view,arch_db:auth_api_key.auth_api_key_form_view
+msgid "Generate Random Token"
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model,name:auth_api_key.model_ir_http
msgid "HTTP Routing"
diff --git a/auth_api_key/i18n/ja.po b/auth_api_key/i18n/ja.po
index baf16ead11..2f6c91489f 100644
--- a/auth_api_key/i18n/ja.po
+++ b/auth_api_key/i18n/ja.po
@@ -79,6 +79,11 @@ msgstr ""
msgid "Display Name"
msgstr ""
+#. module: auth_api_key
+#: model_terms:ir.ui.view,arch_db:auth_api_key.auth_api_key_form_view
+msgid "Generate Random Token"
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model,name:auth_api_key.model_ir_http
msgid "HTTP Routing"
diff --git a/auth_api_key/i18n/zh_CN.po b/auth_api_key/i18n/zh_CN.po
index dd912a4421..e4f022d4ce 100644
--- a/auth_api_key/i18n/zh_CN.po
+++ b/auth_api_key/i18n/zh_CN.po
@@ -79,6 +79,11 @@ msgstr ""
msgid "Display Name"
msgstr ""
+#. module: auth_api_key
+#: model_terms:ir.ui.view,arch_db:auth_api_key.auth_api_key_form_view
+msgid "Generate Random Token"
+msgstr ""
+
#. module: auth_api_key
#: model:ir.model,name:auth_api_key.model_ir_http
msgid "HTTP Routing"
From c461fc7c990ed1488f5b73555d5e76820c12c316 Mon Sep 17 00:00:00 2001
From: mymage
Date: Mon, 27 Jul 2026 09:34:12 +0000
Subject: [PATCH 102/107] Translated using Weblate (Italian)
Currently translated at 100.0% (26 of 26 strings)
Translation: server-auth-19.0/server-auth-19.0-auth_api_key
Translate-URL: https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_api_key/it/
---
auth_api_key/i18n/it.po | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/auth_api_key/i18n/it.po b/auth_api_key/i18n/it.po
index 1798529e51..6786d9b125 100644
--- a/auth_api_key/i18n/it.po
+++ b/auth_api_key/i18n/it.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
-"PO-Revision-Date: 2026-07-20 08:46+0000\n"
+"PO-Revision-Date: 2026-07-27 11:46+0000\n"
"Last-Translator: mymage \n"
"Language-Team: none\n"
"Language: it\n"
@@ -84,7 +84,7 @@ msgstr "Nome visualizzato"
#. module: auth_api_key
#: model_terms:ir.ui.view,arch_db:auth_api_key.auth_api_key_form_view
msgid "Generate Random Token"
-msgstr ""
+msgstr "Genera token casuale"
#. module: auth_api_key
#: model:ir.model,name:auth_api_key.model_ir_http
From d776c499fc5b4214b111a06642184268d157f538 Mon Sep 17 00:00:00 2001
From: Moises Lopez
Date: Fri, 14 Aug 2026 23:42:21 +0000
Subject: [PATCH 103/107] [FIX] auth_api_key: strong test password
The test creates its user with a 4 character password. That is fine for this
module alone, but the OCA CI installs every module of the repository into a
single database, and password_security depends on auth_password_policy_signup,
hence on auth_password_policy, whose data file installs a minimum length of 8:
- https://github.com/odoo/odoo/blob/13e9e827dc21103052e8607d16f23c07adeb5634/addons/auth_password_policy/data/defaults.xml#L5
so setUpClass fails with:
UserError: Your password must contain at least 8 characters and only has 4.
Checked with an A/B run: the module is green on its own and red as soon as
password_security shares the database.
---
auth_api_key/tests/test_controllers.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/auth_api_key/tests/test_controllers.py b/auth_api_key/tests/test_controllers.py
index b965d1b49e..be4578d309 100644
--- a/auth_api_key/tests/test_controllers.py
+++ b/auth_api_key/tests/test_controllers.py
@@ -17,7 +17,9 @@ def setUpClass(cls):
cls.env,
name="Test User",
login="test",
- password="test",
+ # Strong enough for password_security, which lands in the same
+ # database on the CI and enforces its policy on every user.
+ password="Test!2345",
email="test@test.com",
group_ids=[cls.env.ref("base.group_user").id],
company_id=cls.env.company.id,
From 612f85fd7ee6b1509cbc957a1c8ad370cda9c7f7 Mon Sep 17 00:00:00 2001
From: Carlos Dauden
Date: Mon, 9 Nov 2026 09:08:15 +0100
Subject: [PATCH 104/107] [IMP] Remove redundant field strings
The pylint-odoo version of template v1.48 makes attribute-string-redundant (W8113) mandatory. The removed labels are the ones Odoo already generates from the field name, so the UI does not change.
---
auth_api_key/models/auth_api_key.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 63eef6b735..69a3b7378b 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -20,7 +20,6 @@ class AuthApiKey(models.Model):
)
user_id = fields.Many2one(
comodel_name="res.users",
- string="User",
required=True,
help="""The user used to process the requests authenticated by
the api key""",
From 98b0c584385033449d6523e07e881416470a319a Mon Sep 17 00:00:00 2001
From: OCA-git-bot
Date: Thu, 12 Nov 2026 07:40:58 +0000
Subject: [PATCH 105/107] [BOT] post-merge updates
---
auth_api_key/README.rst | 2 +-
auth_api_key/__manifest__.py | 2 +-
auth_api_key/static/description/index.html | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/auth_api_key/README.rst b/auth_api_key/README.rst
index cd03129c30..a36c6f24a5 100644
--- a/auth_api_key/README.rst
+++ b/auth_api_key/README.rst
@@ -11,7 +11,7 @@ Auth Api Key
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:e7679893d3301998264999e637352ed54ac21f411be14f01b7f8b2ab102b3b50
+ !! source digest: sha256:08a9e73e58d720eae5936fe3c94d7f4694c4613c80039ecf33ed5f68392c801c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index 9f480f74f5..69a6eaa8f8 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -5,7 +5,7 @@
"name": "Auth Api Key",
"summary": """
Authenticate http requests from an API key""",
- "version": "19.0.1.1.0",
+ "version": "19.0.1.1.1",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-auth",
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
index 2eb3f9372f..7570b03731 100644
--- a/auth_api_key/static/description/index.html
+++ b/auth_api_key/static/description/index.html
@@ -3,7 +3,7 @@
-README.rst
+Auth Api Key