Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
35f970f
New generic module du define REST services
lmignon Jan 31, 2018
54574c0
auth_api_key: New module to provide authentication by api_key
lmignon Jan 31, 2018
6df5abd
auth_api_key: Remove useless code
lmignon Feb 2, 2018
8e40120
Update the auth_api_key for keychan 10.0.2 (renamed method)
RobinetDenisAcsone Feb 19, 2018
52dd889
Fix the authentification method and show the user_id on the form
RobinetDenisAcsone Feb 19, 2018
ede3c04
refactor code in order to use generic code from base_rest instead of …
sebastienbeau Feb 25, 2018
c97e7b3
fix wrong name in selection box
sebastienbeau Aug 29, 2018
ff092b8
Since keychain 10.0.2.0.1 there is a default validation method
hparfr Oct 17, 2018
06fc2fa
Keychain removed
qgroulard Nov 6, 2018
7ed704e
Update Readme with more details
qgroulard Nov 8, 2018
b746c22
Quick fix CONFIGURE.rst
qgroulard Nov 8, 2018
de14ad0
Developmet status: Beta
qgroulard Nov 8, 2018
d00d90c
[FIX] auth_api_key: fix api and flake8
lmignon Nov 13, 2018
5fb3429
[MIG] server_auth from 10 to 12
sbidoul Nov 20, 2018
45127d5
auth_api_key: add description to model
sbidoul Nov 20, 2018
3d092f6
[CHG] auth_api_key is LGPL
sbidoul Nov 21, 2018
b77aeeb
Use consteq to compare keys
ap-wtioit Nov 30, 2018
5348741
[UPD] README.rst
OCA-git-bot Feb 14, 2019
d703fc0
[IMP] ADD possibility to save api keys in database by using server.en…
mourad-ehm Jul 18, 2019
19deb88
[FIX] login_name error
mourad-ehm Jul 18, 2019
55d00a8
[IMP] make auth_api_key compatible in multi-db
sebastienbeau Jul 19, 2019
597c233
[UPD] README.rst
OCA-git-bot Jul 29, 2019
ef3ce97
[FIX] auth_api_key: Fix tests according to last changes and add views…
lmignon Sep 20, 2019
c3de2d6
[IMP] auth_api_key: Ensures backward compatibility
lmignon Sep 27, 2019
09b8440
[FIX] auth_api_key: Cache must be cleared if the user_id is modified
lmignon Sep 27, 2019
3c0c720
[IMP] auth_api_key: Improves key field description
lmignon Sep 27, 2019
4a172e8
[UPD] README.rst
OCA-git-bot Sep 28, 2019
76f0817
[IMP] auth_api_key: black, isort
Oct 17, 2019
a0df94d
[MIG] auth_api_key: Migration to 13.0
Oct 17, 2019
0fb0151
[UPD] Update auth_api_key.pot
oca-travis Oct 29, 2019
4f81fac
[UPD] README.rst
OCA-git-bot Oct 29, 2019
c10d9dc
pre-commit update
OCA-git-bot Mar 14, 2020
f0510eb
[MIG] auth_api_key: Migration to 14.0
chafique-delli Oct 12, 2020
49f1beb
[UPD] Update auth_api_key.pot
oca-travis Dec 21, 2020
8e424c0
[UPD] README.rst
OCA-git-bot Dec 21, 2020
c5b6911
Added translation using Weblate (Italian)
primes2h Feb 12, 2021
d30c2dc
Translated using Weblate (Italian)
primes2h Feb 12, 2021
e2f748d
[14.0][IMP] auth_api_key: Allow to search on every key even if void
rousseldenis Sep 9, 2021
2338dfd
auth_api_key 14.0.1.0.1
OCA-git-bot Sep 10, 2021
fc92185
auth_api_key: drop old migration
simahawk Sep 24, 2021
c3254e7
auth_api_key: get rid of server env
simahawk Sep 24, 2021
ed3c2c9
auth_api_key: 14.0.2.0.0
simahawk Sep 24, 2021
0e58a4e
[UPD] Update auth_api_key.pot
oca-travis Sep 27, 2021
6ee7396
[UPD] README.rst
OCA-git-bot Sep 27, 2021
4281851
auth_api_key 14.0.2.0.1
OCA-git-bot Sep 27, 2021
5f8baf8
Update translation files
oca-transbot Sep 27, 2021
1320efe
[MIG] auth_api_key: Migration to 15.0
yankinmax Nov 24, 2021
4e07790
[UPD] Update auth_api_key.pot
Nov 30, 2021
2ad4a6a
auth_api_key: fix archived user allowed key
TDu Jul 22, 2022
8f11ad7
[UPD] Update auth_api_key.pot
Jul 26, 2022
120003e
auth_api_key 15.0.1.1.0
OCA-git-bot Jul 26, 2022
4e03c27
Update translation files
oca-transbot Jul 26, 2022
f536cd9
Revert "Merge PR #398 into 15.0"
TDu Jul 26, 2022
e7397b4
Revert "[UPD] Update auth_api_key.pot"
TDu Jul 26, 2022
412b74c
Revert "Update translation files"
TDu Jul 26, 2022
21814be
auth_api_key 15.0.1.1.1
OCA-git-bot Jul 28, 2022
59198b5
Update translation files
oca-transbot Jul 28, 2022
ffaca14
[IMP] auth_api_key: pre-commit stuff
benoit-bertholon Nov 29, 2022
628c813
[MIG] auth_api_key: Migration to 16.0
benoit-bertholon Nov 29, 2022
bb2211e
[UPD] Update auth_api_key.pot
Dec 5, 2022
4333931
[UPD] README.rst
OCA-git-bot Dec 5, 2022
3a686d1
Update translation files
weblate Dec 5, 2022
b37df31
[UPD] README.rst
OCA-git-bot Sep 3, 2023
8097e41
[IMP] auth_api_key: pre-commit auto fixes
chrisb-c01 Dec 16, 2023
e554986
[MIG] auth_api_key: Migration to 17.0
chrisb-c01 Dec 16, 2023
06f4a98
[UPD] Update auth_api_key.pot
Jan 26, 2024
32c99b5
[BOT] post-merge updates
OCA-git-bot Jan 26, 2024
7f36068
Update translation files
weblate Feb 3, 2024
b48277f
Translated using Weblate (Italian)
mymage Apr 3, 2024
54b6758
Translated using Weblate (Italian)
mymage Aug 17, 2024
5b7ecfa
[14.0] auth_api_key: allow to update api key from form view and hide …
petrus-v Jun 26, 2023
2af16a7
auth_api_key: archive key when user is archived
TDu Mar 21, 2023
8b872fc
auth_api_key: add option to auto archive key with user
TDu Mar 27, 2023
425ca36
[IMP] auth_api_key: apply pre-commit auto fixes
thienvh332 Oct 8, 2024
59e6793
[MIG] auth_api_key: Migration to 18.0
thienvh332 Oct 8, 2024
d04709b
[UDP] auth_api_key: Update description for reason to keep this module
thienvh332 Oct 10, 2024
acafdfa
[UPD] Update auth_api_key.pot
Oct 11, 2024
566011a
[BOT] post-merge updates
OCA-git-bot Oct 11, 2024
5aeb15e
Update translation files
weblate Oct 11, 2024
ca1e56b
Translated using Weblate (Italian)
mymage Oct 13, 2024
74d1f40
[IMP] update dotfiles
OCA-git-bot Oct 20, 2024
f17296f
Added translation using Weblate (Chinese (Simplified) (zh_CN))
xtanuiha Apr 13, 2025
5764be5
[18.0][FIX] auth_api_key: Use 401 for unauthorized user
anusriNPS Jun 16, 2025
d7760f9
[BOT] post-merge updates
OCA-git-bot Jun 16, 2025
a026035
[IMP] auth_api_key: pre-commit auto fixes
arantxa-s73 Dec 4, 2025
d23f046
[MIG] auth_api_key: Migration to 19.0
arantxa-s73 Dec 4, 2025
4ad2acb
[UPD] Update auth_api_key.pot
Apr 21, 2026
87a0737
[BOT] post-merge updates
OCA-git-bot Apr 21, 2026
86a6a97
Added translation using Weblate (Japanese)
Ryoko04 Apr 22, 2026
e632c65
[IMP] auth_api_key: add tests for controllers
ivantodorovich May 20, 2026
01a1349
[FIX] auth_api_key: report allowed header in cors OPTIONS
ivantodorovich May 20, 2026
8d9eec9
[BOT] post-merge updates
OCA-git-bot May 26, 2026
1ba1c9f
[19.0][IMP] auth_api_key: neutralize API keys
yankinmax Jun 11, 2026
4b11046
[UPD] Update auth_api_key.pot
Jul 15, 2026
a21f5ac
[BOT] post-merge updates
OCA-git-bot Jul 15, 2026
c0c91be
Update translation files
weblate Jul 15, 2026
1042dce
Translated using Weblate (Italian)
mymage Jul 20, 2026
10d66c2
[IMP] auth_api_key: generate API keys automatically
yankinmax Jun 11, 2026
66adf7b
[UPD] Update auth_api_key.pot
Jul 23, 2026
3982c0b
[BOT] post-merge updates
OCA-git-bot Jul 23, 2026
48f32ef
Update translation files
weblate Jul 23, 2026
c461fc7
Translated using Weblate (Italian)
mymage Jul 27, 2026
d776c49
[FIX] auth_api_key: strong test password
moylop260 Aug 14, 2026
612f85f
[IMP] Remove redundant field strings
carlosdauden Nov 9, 2026
98b0c58
[BOT] post-merge updates
OCA-git-bot Nov 12, 2026
ac2d3dd
[IMP] auth_api_key: pre-commit auto fixes
Nov 19, 2026
af4917f
[MIG] auth_api_key: Migration to 20.0
Nov 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions auth_api_key/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

============
Auth Api Key
============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:08a9e73e58d720eae5936fe3c94d7f4694c4613c80039ecf33ed5f68392c801c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/license-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/20.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-20-0/server-auth-20-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=20.0
:alt: Try me on Runboat

|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.

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

Given these advantages, particularly in use case like system user
authentication, we have decided to keep the ``auth_api_key`` module

**Table of contents**

.. contents::
:local:

Configuration
=============

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.

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:: 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 <https://github.com/OCA/server-auth/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 <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_api_key%0Aversion:%2020.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Denis Robinet <denis.robinet@acsone.eu>
- Laurent Mignon <laurent.mignon@acsone.eu>
- Quentin Groulard <quentin.groulard@acsone.eu>
- Sébastien Beau <sebastien.beau@akretion.com>
- Chafique Delli <chafique.delli@akretion.com>
- Thien Vo Hong <thienvh@trobz.com>

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 <https://github.com/OCA/server-auth/tree/20.0/auth_api_key>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions auth_api_key/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_load_hook
19 changes: 19 additions & 0 deletions auth_api_key/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2018 ACSONE SA/NV
# 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": "20.0.1.0.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-auth",
"development_status": "Production/Stable",
"depends": ["base_setup"],
"post_load": "post_load_hook",
"data": [
"security/ir.access.csv",
"views/auth_api_key.xml",
"views/res_config_settings.xml",
],
}
3 changes: 3 additions & 0 deletions auth_api_key/data/neutralize.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- remove API keys
UPDATE auth_api_key
SET key = NULL;
52 changes: 52 additions & 0 deletions auth_api_key/hooks.py
Original file line number Diff line number Diff line change
@@ -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.dispatcher 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()
163 changes: 163 additions & 0 deletions auth_api_key/i18n/auth_api_key.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# 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: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \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_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"
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
#. 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 ""
"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 ""
Loading