forked from OCA/rest-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] base_rest_auth_api_key: Add support for the auth_jwt security p…
…olicy into the openapi documentation
- Loading branch information
Showing
13 changed files
with
594 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": []}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Laurent Mignon <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.