Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b39686b
Add endpoint_auth_api_key
simahawk Sep 24, 2021
4a9fb9b
[ADD] icon.png
OCA-git-bot Nov 2, 2021
7efd4e2
endpoint_auth_api_key: add btn to manage groups
simahawk Nov 12, 2021
f0c3344
endpoint_auth_api_key: show group mgmt btn if needed
simahawk Dec 28, 2021
fb03d54
endpoint_auth_api_key 14.0.1.1.0
OCA-git-bot Jan 12, 2022
01c9854
Misc fix of authorship name
simahawk Jan 14, 2022
75206d1
endpoint_auth_api_key 14.0.1.1.1
OCA-git-bot Jan 14, 2022
2d80c22
[FIX] Fix access right issues when using actions
sebalix Jan 31, 2022
9c16fd1
endpoint_auth_api_key 14.0.1.1.2
OCA-git-bot Jan 31, 2022
e124abe
endpoint_auth_api_key: move to OCA/web-api
simahawk Aug 1, 2022
2b462d8
endpoint_auth_api_key: adapt to new sync behavior
simahawk Feb 16, 2023
3c98972
[MIG] endpoint_auth_api_key: Migrate to version 16.0
Dec 26, 2023
26d0f59
[UPD] Update endpoint_auth_api_key.pot
Mar 27, 2024
6329428
Added translation using Weblate (Italian)
mymage Apr 2, 2024
814e611
Translated using Weblate (Italian)
mymage Apr 2, 2024
36a10da
endpoint: add basic mixin view
simahawk Jul 23, 2024
696eb7c
[UPD] Update endpoint_auth_api_key.pot
Jul 26, 2024
024cfb7
[BOT] post-merge updates
OCA-git-bot Jul 26, 2024
460339c
Update translation files
weblate Jul 26, 2024
91eb536
endpoint_*: fix mixin view override
simahawk Aug 8, 2024
a38fb46
[BOT] post-merge updates
OCA-git-bot Aug 8, 2024
e6ed52d
[IMP] endpoint_auth_api_key: pre-commit auto fixes
SilvioC2C Mar 18, 2025
130458d
[MIG] endpoint_auth_api_key: Migrate to version 17.0
SilvioC2C Mar 18, 2025
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
99 changes: 99 additions & 0 deletions endpoint_auth_api_key/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
=====================
Endpoint Auth API key
=====================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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%2Fweb--api-lightgray.png?logo=github
:target: https://github.com/OCA/web-api/tree/17.0/endpoint_auth_api_key
:alt: OCA/web-api
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-api-17-0/web-api-17-0-endpoint_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/web-api&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Provide API key auth for endpoints.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web-api/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/web-api/issues/new?body=module:%20endpoint_auth_api_key%0Aversion:%2017.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
-------

* Camptocamp

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

- Simone Orsi <simone.orsi@camptocamp.com>

- `Trobz <https://trobz.com>`__:

- Son Ho <sonhd@trobz.com>

Other credits
-------------

The migration of this module from 14.0 to 16.0 was financially supported
by Camptocamp

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.

.. |maintainer-simahawk| image:: https://github.com/simahawk.png?size=40px
:target: https://github.com/simahawk
:alt: simahawk

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-simahawk|

This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/17.0/endpoint_auth_api_key>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions endpoint_auth_api_key/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions endpoint_auth_api_key/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2021 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Endpoint Auth API key",
"summary": """Provide API key auth for endpoints.""",
"version": "17.0.1.0.0",
"license": "LGPL-3",
"development_status": "Alpha",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["simahawk"],
"website": "https://github.com/OCA/web-api",
"depends": ["endpoint", "auth_api_key_group"],
"demo": ["demo/api_key_demo.xml", "demo/endpoint_demo.xml"],
"data": ["views/endpoint_view.xml"],
}
22 changes: 22 additions & 0 deletions endpoint_auth_api_key/demo/api_key_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">

<record id="auth_api_key_demo" model="auth.api.key">
<field name="name">Endpoint API key demo</field>
<field name="key">cZ6dF2UQwNcm</field>
<field name="user_id" ref="base.user_demo" />
</record>

<record id="auth_api_key_demo2" model="auth.api.key">
<field name="name">Endpoint API key demo 2</field>
<field name="key">kV47QyOTC5mS</field>
<field name="user_id" ref="base.user_demo" />
</record>

<record id="auth_api_key_group_demo" model="auth.api.key.group">
<field name="name">Demo Group 1</field>
<field name="code">demo_group1</field>
<field name="auth_api_key_ids" eval="[(4, ref('auth_api_key_demo'))]" />
</record>

</odoo>
19 changes: 19 additions & 0 deletions endpoint_auth_api_key/demo/endpoint_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="endpoint_demo_1" model="endpoint.endpoint">
<field name="name">Demo Endpoint - auth api key</field>
<field name="route">/demo/api/key</field>
<field name="request_method">GET</field>
<field name="auth_type">api_key</field>
<field
name="auth_api_key_group_ids"
eval="[(4, ref('auth_api_key_group_demo'))]"
/>
<field name="exec_mode">code</field>
<field name="code_snippet">
result = {"response": Response("ok")}
</field>
</record>

</odoo>
30 changes: 30 additions & 0 deletions endpoint_auth_api_key/i18n/endpoint_auth_api_key.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * endpoint_auth_api_key
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.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: endpoint_auth_api_key
#: model:ir.model.fields,field_description:endpoint_auth_api_key.field_endpoint_endpoint__auth_api_key_group_ids
#: model:ir.model.fields,field_description:endpoint_auth_api_key.field_endpoint_mixin__auth_api_key_group_ids
msgid "Allowed API key groups"
msgstr ""

#. module: endpoint_auth_api_key
#: model:ir.model,name:endpoint_auth_api_key.model_endpoint_mixin
msgid "Endpoint mixin"
msgstr ""

#. module: endpoint_auth_api_key
#: model_terms:ir.ui.view,arch_db:endpoint_auth_api_key.endpoint_mixin_form_view
msgid "Manage groups"
msgstr ""
33 changes: 33 additions & 0 deletions endpoint_auth_api_key/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * endpoint_auth_api_key
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-04-02 12:35+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: endpoint_auth_api_key
#: model:ir.model.fields,field_description:endpoint_auth_api_key.field_endpoint_endpoint__auth_api_key_group_ids
#: model:ir.model.fields,field_description:endpoint_auth_api_key.field_endpoint_mixin__auth_api_key_group_ids
msgid "Allowed API key groups"
msgstr "Consenti gruppi chiavi API"

#. module: endpoint_auth_api_key
#: model:ir.model,name:endpoint_auth_api_key.model_endpoint_mixin
msgid "Endpoint mixin"
msgstr "Mixin endpoint"

#. module: endpoint_auth_api_key
#: model_terms:ir.ui.view,arch_db:endpoint_auth_api_key.endpoint_mixin_form_view
msgid "Manage groups"
msgstr "Gestione gruppi"
1 change: 1 addition & 0 deletions endpoint_auth_api_key/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import endpoint_mixin
40 changes: 40 additions & 0 deletions endpoint_auth_api_key/models/endpoint_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2021 Camptocamp SA
# @author: Simone Orsi <simone.orsi@camptocamp.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import werkzeug

from odoo import fields, models


class EndpointMixin(models.AbstractModel):
_inherit = "endpoint.mixin"

auth_api_key_group_ids = fields.Many2many(
comodel_name="auth.api.key.group",
string="Allowed API key groups",
)

def _selection_auth_type(self):
return super()._selection_auth_type() + [("api_key", "API key")]

def _validate_request(self, request):
super()._validate_request(request)
if self.auth_type == "api_key":
self._validate_api_key(request)
return

def _validate_api_key(self, request):
key_id = request.auth_api_key_id
if key_id not in self._allowed_api_key_ids():
self._logger.error("API key %s not allowed on %s", key_id, self.route)
raise werkzeug.exceptions.Forbidden()

def _allowed_api_key_ids(self):
return self.auth_api_key_group_ids.auth_api_key_ids.ids

def action_view_api_key_groups(self):
xmlid = "auth_api_key_group.auth_api_key_group_act_window"
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
action["domain"] = [("id", "in", self.auth_api_key_group_ids.ids)]
return action

Check warning on line 40 in endpoint_auth_api_key/models/endpoint_mixin.py

View check run for this annotation

Codecov / codecov/patch

endpoint_auth_api_key/models/endpoint_mixin.py#L37-L40

Added lines #L37 - L40 were not covered by tests
3 changes: 3 additions & 0 deletions endpoint_auth_api_key/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
5 changes: 5 additions & 0 deletions endpoint_auth_api_key/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Simone Orsi \<<simone.orsi@camptocamp.com>\>

- [Trobz](https://trobz.com):

> - Son Ho \<<sonhd@trobz.com>\>
2 changes: 2 additions & 0 deletions endpoint_auth_api_key/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The migration of this module from 14.0 to 16.0 was financially supported
by Camptocamp
1 change: 1 addition & 0 deletions endpoint_auth_api_key/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Provide API key auth for endpoints.
Binary file added endpoint_auth_api_key/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading