From c4de7178db95c22c7f77b8f039ed21551a927428 Mon Sep 17 00:00:00 2001
From: "Laurent Mignon (ACSONE)"
Date: Wed, 31 Jan 2018 17:30:50 +0100
Subject: [PATCH 01/86] 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 5ddfae429f671885d599430a098a69ef6249a2a9 Mon Sep 17 00:00:00 2001
From: "Laurent Mignon (ACSONE)"
Date: Thu, 1 Feb 2018 00:20:26 +0100
Subject: [PATCH 02/86] 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~AW`Y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JYT(#@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
+ []
+ {}
+
+
+
+
+
From 806d56a14f0c50c3b93c1a38650d800727e2d8b4 Mon Sep 17 00:00:00 2001
From: "Laurent Mignon (ACSONE)"
Date: Fri, 2 Feb 2018 16:26:45 +0100
Subject: [PATCH 03/86] 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 0c349e5b4b0103e0a5c9e758c7ec4a6d88610358 Mon Sep 17 00:00:00 2001
From: "Denis Robinet (ACSONE)"
Date: Mon, 19 Feb 2018 15:30:01 +0100
Subject: [PATCH 04/86] 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 0f7f8818a5ef3ac1ac2a9ee5c7c7a745cbdd8b08 Mon Sep 17 00:00:00 2001
From: "Denis Robinet (ACSONE)"
Date: Mon, 19 Feb 2018 15:31:24 +0100
Subject: [PATCH 05/86] 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 920ab7e40420a288a4d0021d3a7309a82b72d54f 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 06/86] 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 42d9d6d42ec4a63aaf19b334b6bb14bc8b75fa3a 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 07/86] 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 70c8b577e9e7d1bfd2ceb949a057f0479dbebd0d Mon Sep 17 00:00:00 2001
From: hparfr
Date: Wed, 17 Oct 2018 12:51:51 +0200
Subject: [PATCH 08/86] 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 09740717757e6ab580d09ed36f95ebb133086e55 Mon Sep 17 00:00:00 2001
From: Quentin Groulard
Date: Tue, 6 Nov 2018 12:34:52 +0100
Subject: [PATCH 09/86] 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
- []
- {}
-
-
-
-
-
From 0c059b05a4884a6f9ba437f0e5b88b2669097193 Mon Sep 17 00:00:00 2001
From: Quentin Groulard
Date: Thu, 8 Nov 2018 11:06:58 +0100
Subject: [PATCH 10/86] 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 cc9159cbb21e566871c148fe9be18083b1abdf2f 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 11/86] 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 1eeaea80e3e50b2898a2820fdfa2827095d3f587 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 12/86] 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 9ca0b0ef5df98aff18d5153db4306b97867c490f Mon Sep 17 00:00:00 2001
From: "Laurent Mignon (ACSONE)"
Date: Tue, 13 Nov 2018 11:32:39 +0100
Subject: [PATCH 13/86] [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.
+
Table of contents
+
+
+
+
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
+
+
+
+
+
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
+
+
+
+
+
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.
+
+
+
+
+
+
+
+
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.
+
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/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 acdbd98106a169fe9c4eb893e73b76b4d362b835 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 14/86] [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 ca95c5aef1d6b43d7e5b69543cb58dedb6af0498 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 15/86] 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 a09eed26c0fa2e89808fa6094af5118fe20001f8 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 16/86] [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 f75eafbc1f994c300b54c64ad83b8e4fe1995e8a 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 17/86] 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 55ba60da4d4e14e483b854fab8324d630e998d03 Mon Sep 17 00:00:00 2001
From: OCA-git-bot
Date: Thu, 14 Feb 2019 10:29:14 +0000
Subject: [PATCH 18/86] [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.
@@ -413,7 +413,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 smashing it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -440,7 +440,7 @@
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.
From 2858a7d25bd5b8d3fd80b624c5329d9b34e9a3ef Mon Sep 17 00:00:00 2001
From: Mourad
Date: Thu, 18 Jul 2019 13:47:24 +0200
Subject: [PATCH 19/86] [IMP] ADD possibility to save api keys in database by
using server.env.mixin obj
---
auth_api_key/models/auth_api_key.py | 62 +++++++++++++++++++++--------
1 file changed, 45 insertions(+), 17 deletions(-)
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index 1c435a09f0..8059bd304c 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -3,36 +3,64 @@
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
-class AuthApiKey(models.TransientModel):
+class AuthApiKey(models.Model):
_name = "auth.api.key"
+ _inherit = "server.env.mixin"
_description = "API Key Retriever"
+ name = fields.Char(required=True)
+ key = fields.Char(required=True)
+ user = fields.Char(required=True)
+
+ _sql_constraints = [
+ ('key_uniq', 'unique(key)', 'API Key Retriever must be unique !'),
+ ]
+
+ @property
+ def _server_env_fields(self):
+ base_fields = super()._server_env_fields
+ api_key_fields = {
+ "key": {},
+ "user": {},
+ }
+ api_key_fields.update(base_fields)
+ return api_key_fields
+
@api.model
@tools.ormcache("api_key")
- def _retrieve_uid_from_api_key(self, api_key):
+ def _retrieve_api_key(self, api_key):
if not self.env.user.has_group("base.group_system"):
raise AccessError(_("User is not allowed"))
+ ap_keys = self.search([])
+ # api key are a computed field in the context of server env
+ # so we can't use a domain in search method
+ key = False
+ for ap_key in ap_keys:
+ if consteq(api_key, ap_key.key):
+ key = ap_key
+
+ if not key:
+ raise ValidationError(
+ _("The key %s is not defined") % api_key)
- for section in serv_config.sections():
- if section.startswith("api_key_") and serv_config.has_option(
- section, "key"
- ):
- if not consteq(api_key, serv_config.get(section, "key")):
- continue
+ return key
+
+ @api.model
+ @tools.ormcache("api_key")
+ def _retrieve_uid_from_api_key(self, api_key):
+ ap_key = self._retrieve_api_key(api_key)
+ uid = self.env["res.users"].search(
+ [("login", "=", ap_key.user)]).id
- 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)
- if not uid:
- raise ValidationError(
- _("No user found with login %s") % login_name)
+ return uid
+ return False
- return uid
- return False
From 03245a74cfd40a74a2ca9b48146c9a67d4c1c812 Mon Sep 17 00:00:00 2001
From: Mourad
Date: Thu, 18 Jul 2019 13:52:33 +0200
Subject: [PATCH 20/86] [FIX] login_name error
---
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 8059bd304c..e767ff833a 100644
--- a/auth_api_key/models/auth_api_key.py
+++ b/auth_api_key/models/auth_api_key.py
@@ -59,7 +59,7 @@ def _retrieve_uid_from_api_key(self, api_key):
if not uid:
raise ValidationError(
- _("No user found with login %s") % login_name)
+ _("No user found with login %s") % ap_key.user)
return uid
return False
From d80c99652c743157b251531e757f0528dae639f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20BEAU?=
Date: Fri, 19 Jul 2019 17:13:54 +0200
Subject: [PATCH 21/86] [IMP] make auth_api_key compatible in multi-db
Api key is now based on the new version of server env
Key belong to a specifiv database that can be requested based on the
domain name.
Just setup the db_filter with "%d^" to filter based on domain name
---
auth_api_key/__manifest__.py | 2 +-
auth_api_key/models/auth_api_key.py | 64 +++++++++++------------
auth_api_key/models/ir_http.py | 8 +--
auth_api_key/security/ir.model.access.csv | 2 +
4 files changed, 39 insertions(+), 37 deletions(-)
create mode 100644 auth_api_key/security/ir.model.access.csv
diff --git a/auth_api_key/__manifest__.py b/auth_api_key/__manifest__.py
index 896e30b8a9..c75d1f01c0 100644
--- a/auth_api_key/__manifest__.py
+++ b/auth_api_key/__manifest__.py
@@ -12,6 +12,6 @@
"website": "https://acsone.eu/",
"development_status": "Beta",
"depends": ["server_environment"],
- "data": [],
+ "data": ['security/ir.model.access.csv'],
"demo": [],
}
diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py
index e767ff833a..df979551d4 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, models, tools, _
+from odoo import api, fields, models, tools, _
from odoo.tools import consteq
@@ -15,52 +15,52 @@ class AuthApiKey(models.Model):
name = fields.Char(required=True)
key = fields.Char(required=True)
- user = fields.Char(required=True)
-
- _sql_constraints = [
- ('key_uniq', 'unique(key)', 'API Key Retriever must be unique !'),
- ]
+ user_id = fields.Many2one(
+ comodel_name="res.users",
+ string="User",
+ required=True)
@property
def _server_env_fields(self):
base_fields = super()._server_env_fields
api_key_fields = {
"key": {},
- "user": {},
}
api_key_fields.update(base_fields)
return api_key_fields
@api.model
- @tools.ormcache("api_key")
- def _retrieve_api_key(self, api_key):
+ def _retrieve_api_key(self, key):
+ return self.browse(self._retrieve_api_key_id(key))
+
+ @api.model
+ @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"))
- ap_keys = self.search([])
- # api key are a computed field in the context of server env
- # so we can't use a domain in search method
- key = False
- for ap_key in ap_keys:
- if consteq(api_key, ap_key.key):
- key = ap_key
-
- if not key:
- raise ValidationError(
- _("The key %s is not defined") % api_key)
-
- return key
+ for api_key in self.search([]):
+ if consteq(key, api_key.key):
+ return api_key.id
+ raise ValidationError(_("The key %s is not allowed") % key)
@api.model
- @tools.ormcache("api_key")
- def _retrieve_uid_from_api_key(self, api_key):
- ap_key = self._retrieve_api_key(api_key)
- uid = self.env["res.users"].search(
- [("login", "=", ap_key.user)]).id
+ @tools.ormcache("key")
+ def _retrieve_uid_from_api_key(self, key):
+ return self._retrieve_api_key(key).user_id.id
- if not uid:
- raise ValidationError(
- _("No user found with login %s") % ap_key.user)
+ def _clear_key_cache(self):
+ self._retrieve_api_key_id.clear_cache()
+ self._retrieve_uid_from_api_key.clear_cache()
- return uid
- return False
+ @api.model
+ def create(self, vals):
+ record = super(AuthApikey, self).create(vals)
+ if 'key' in vals:
+ self._clear_key_cache()
+ return record
+ def write(self, vals):
+ super(AuthApikey, self).write(vals)
+ if 'key' in vals:
+ self._clear_key_cache()
+ return True
diff --git a/auth_api_key/models/ir_http.py b/auth_api_key/models/ir_http.py
index 1e6638a07d..f28183abb0 100644
--- a/auth_api_key/models/ir_http.py
+++ b/auth_api_key/models/ir_http.py
@@ -22,16 +22,16 @@ 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)
- if uid:
+ api = request.env["auth.api.key"]._retrieve_api_key(api_key)
+ if api:
# 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 = uid
+ request.uid = api.user_id.id
request.auth_api_key = api_key
+ request.auth_api_key_id = api.id
return True
_logger.error("Wrong HTTP_API_KEY, access denied")
raise AccessDenied()
diff --git a/auth_api_key/security/ir.model.access.csv b/auth_api_key/security/ir.model.access.csv
new file mode 100644
index 0000000000..b964d8c1de
--- /dev/null
+++ b/auth_api_key/security/ir.model.access.csv
@@ -0,0 +1,2 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_auth_api_key,access_auth_api_key,model_auth_api_key,base.group_system,1,1,1,1
From 38369f86f95ca7b590ca412df65061e8228f3b17 Mon Sep 17 00:00:00 2001
From: OCA-git-bot
Date: Mon, 29 Jul 2019 03:37:25 +0000
Subject: [PATCH 22/86] [UPD] README.rst
---
auth_api_key/static/description/index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/auth_api_key/static/description/index.html b/auth_api_key/static/description/index.html
index f70369a5af..8a5bd04cac 100644
--- a/auth_api_key/static/description/index.html
+++ b/auth_api_key/static/description/index.html
@@ -3,7 +3,7 @@
-
+
Auth Api Key
-
-
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
@@ -407,7 +412,7 @@
Auth Api Key
-
+
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.
@@ -415,20 +420,20 @@
auth_api_key_server_env.
-
+
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):
+class MyController(Controller):
@route('/my_service', auth='api_key', ...)
- def my_service(self, *args, **kwargs):
+ def my_service(self, *args, **kwargs):
pass
-
+
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 @@
Do not contact contributors directly about support or help with technical issues.
-
+
-
+
The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.
-
+
This module is maintained by the OCA.
@@ -473,5 +478,6 @@
+
From be66a28a6e27bcf75c08cf2fdf0d31053a7c3384 Mon Sep 17 00:00:00 2001
From: arantxa-s73
Date: Thu, 4 Dec 2025 08:52:14 +0100
Subject: [PATCH 85/86] [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 5a6cd9aea1c3cc274ea45c180549776ef8840d31 Mon Sep 17 00:00:00 2001
From: arantxa-s73
Date: Thu, 4 Dec 2025 09:40:16 +0100
Subject: [PATCH 86/86] [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 @@ Auth Api Key
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:78e3946b0dbb81bb6fbf6c434aaf5214faec00449a765c2f41e321b65024ba05
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-

+

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
@@ -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.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -473,7 +473,7 @@
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/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
)