Skip to content

Commit

Permalink
[ADD] base_rest_auth_api_key: Add support for the auth_jwt security p…
Browse files Browse the repository at this point in the history
…olicy into the openapi documentation
  • Loading branch information
lmignon committed Jul 29, 2021
1 parent 5ba68d5 commit e042565
Show file tree
Hide file tree
Showing 13 changed files with 594 additions and 0 deletions.
83 changes: 83 additions & 0 deletions base_rest_auth_jwt/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
==================
Base Rest Auth Jwt
==================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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-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/14.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-14-0/rest-framework-14-0-base_rest_auth_jwt
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/271/14.0
:alt: Try me on Runbot

|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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest_auth_jwt%0Aversion:%2014.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 <[email protected]>

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/14.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": "14.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>=4.0.0",
]
},
}
Empty file.
37 changes: 37 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,37 @@
# Copyright 2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from apispec import BasePlugin


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

def init_spec(self, spec):
super(RestMethodSecurityPlugin, self).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")
if not routing:
super(RestMethodSecurityPlugin, self).operation_helper(
path, operations, **kwargs
)
if not operations:
return
auth = routing.get("auth", self.spec._params.get("default_auth"))
if auth and auth.startswith("jwt"):
for _method, params in operations.items():
security = params.setdefault("security", [])
security.append({"jwt": []})
1 change: 1 addition & 0 deletions base_rest_auth_jwt/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import service
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(BaseRestService, self)._get_api_spec(**params)
plugin = RestMethodSecurityPlugin(self)
plugin.init_spec(spec)
spec.plugins.append(plugin)
return spec
1 change: 1 addition & 0 deletions base_rest_auth_jwt/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Laurent Mignon <[email protected]>
3 changes: 3 additions & 0 deletions base_rest_auth_jwt/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

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

0 comments on commit e042565

Please sign in to comment.