Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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/18.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-18-0/web-api-18-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=18.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:%2018.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/18.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": "18.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"],
}
20 changes: 20 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,20 @@
<?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>
17 changes: 17 additions & 0 deletions endpoint_auth_api_key/demo/endpoint_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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")]

Check warning on line 19 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#L19

Added line #L19 was not covered by tests

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