Skip to content
Open
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
85 changes: 85 additions & 0 deletions base_rest_auth_jwt/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
==================
Base Rest Auth Jwt
==================

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

.. |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-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%2Frest--framework-lightgray.png?logo=github
:target: https://github.com/OCA/rest-framework/tree/18.0/base_rest_auth_jwt
:alt: OCA/rest-framework
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest_auth_jwt
: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/rest-framework&target_branch=18.0
:alt: Try me on Runboat

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

This technical addon extend base_rest to add the support for auth_jwt
authentication mechanism into the generated openapi documentation.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/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/rest-framework/issues/new?body=module:%20base_rest_auth_jwt%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
-------

* ACSONE SA/NV

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

- Laurent Mignon <laurent.mignon@acsone.eu>

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-lmignon| image:: https://github.com/lmignon.png?size=40px
:target: https://github.com/lmignon
:alt: lmignon

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

|maintainer-lmignon|

This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/base_rest_auth_jwt>`_ 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 base_rest_auth_jwt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import components
22 changes: 22 additions & 0 deletions base_rest_auth_jwt/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2021 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Base Rest Auth Jwt",
"summary": """
Base Rest: Add support for the auth_jwt security policy into the
openapi documentation""",
"version": "18.0.1.0.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/rest-framework",
"depends": ["base_rest", "auth_jwt"],
"maintainers": ["lmignon"],
"installable": True,
"auto_install": True,
"external_dependencies": {
"python": [
"apispec",
]
},
}
Empty file.
43 changes: 43 additions & 0 deletions base_rest_auth_jwt/apispec/rest_method_security_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from apispec import BasePlugin

from odoo.addons.base_rest.tools import ROUTING_DECORATOR_ATTR


class RestMethodSecurityPlugin(BasePlugin):
def __init__(self, service):
super().__init__()
self._service = service

# pylint: disable=W8110
def init_spec(self, spec):
super().init_spec(spec)
self.spec = spec
self.openapi_version = spec.openapi_version
jwt_scheme = {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT",
"name": "jwt",
"description": "Enter JWT Bearer Token ** only **",
}
spec.components.security_scheme("jwt", jwt_scheme)

def operation_helper(self, path=None, operations=None, **kwargs):
routing = kwargs.get(ROUTING_DECORATOR_ATTR)
if not routing:
super().operation_helper(path, operations, **kwargs)
if not operations:
return
default_auth = self.spec._params.get("default_auth")
auth = routing.get("auth", default_auth)
if (auth and auth.startswith("jwt")) or (
auth == "public_or_default"
and default_auth
and default_auth.startswith("jwt")
):
for _method, params in operations.items():
security = params.setdefault("security", [])
security.append({"jwt": []})
2 changes: 2 additions & 0 deletions base_rest_auth_jwt/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import auth_jwt_component_context_provider
from . import service
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2021 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).


from odoo.http import request

from odoo.addons.component.core import AbstractComponent, Component


class AbstractAuthJwtAuthenticatedPartnerProvider(AbstractComponent):
_name = "abstract.auth.jwt.authenticated.partner.provider"

def _get_authenticated_partner_id(self):
return request.jwt_partner_id


class BaseRestAuthJwtComponentContextProvider(Component):
_name = "base.rest.auth.jwt.component.context.provider"
_inherit = [
"abstract.auth.jwt.authenticated.partner.provider",
"base.rest.service.context.provider",
]
_usage = "auth_jwt_component_context_provider"
17 changes: 17 additions & 0 deletions base_rest_auth_jwt/components/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2021 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo.addons.component.core import AbstractComponent

from ..apispec.rest_method_security_plugin import RestMethodSecurityPlugin


class BaseRestService(AbstractComponent):
_inherit = "base.rest.service"

def _get_api_spec(self, **params):
spec = super()._get_api_spec(**params)
plugin = RestMethodSecurityPlugin(self)
plugin.init_spec(spec)
spec.plugins.append(plugin)
return spec
13 changes: 13 additions & 0 deletions base_rest_auth_jwt/i18n/base_rest_auth_jwt.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.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"
3 changes: 3 additions & 0 deletions base_rest_auth_jwt/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions base_rest_auth_jwt/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Laurent Mignon \<laurent.mignon@acsone.eu\>
2 changes: 2 additions & 0 deletions base_rest_auth_jwt/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This technical addon extend base_rest to add the support for auth_jwt
authentication mechanism into the generated openapi documentation.
Binary file added base_rest_auth_jwt/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
Loading