Skip to content

Commit a2c060e

Browse files
committed
Merge PR #490 into 18.0
Signed-off-by lmignon
2 parents 73f7adb + 135028d commit a2c060e

14 files changed

Lines changed: 980 additions & 3 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exclude: |
22
(?x)
33
# NOT INSTALLABLE ADDONS
4-
^extendable/|
4+
^fastapi_auth_jwt/|
55
# END NOT INSTALLABLE ADDONS
66
# Files and folders generated by bots, to avoid loops
77
^setup/|/static/description/index\.html$|

base_rest_auth_api_key/static/description/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Base Rest Auth Api Key</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:7c57ea5f8972ccd3fd126f96da0ff252203ec8d51cb0a1f2e4a1b101e730d838
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/18.0/base_rest_auth_api_key"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest_auth_api_key"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/18.0/base_rest_auth_api_key"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest_auth_api_key"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This technical addon extend base_rest to add the support for
379379
auth_api_key authentication mechanism into the generated openapi
380380
documentation.</p>

extendable/tests/common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from contextlib import contextmanager
55

6-
import odoo
76
from odoo import SUPERUSER_ID, api
87
from odoo.modules.registry import Registry
98
from odoo.tests import common

fastapi_auth_jwt/README.rst

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
========================
2+
FastAPI Auth JWT support
3+
========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:2829a34d48a1906819029e7b796d33a1ee2ad2a47693396da96f92ede04ec17d
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
20+
:target: https://github.com/OCA/rest-framework/tree/18.0/fastapi_auth_jwt
21+
:alt: OCA/rest-framework
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-fastapi_auth_jwt
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module provides ``FastAPI`` ``Depends`` to allow authentication
32+
with
33+
`auth_jwt <https://github.com/OCA/server-auth/tree/18.0/auth_jwt>`__.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Usage
41+
=====
42+
43+
The following FastAPI dependencies are provided and importable from
44+
``odoo.addons.fastapi_auth_jwt.dependencies``:
45+
46+
``def auth_jwt_authenticated_payload() -> Payload``
47+
48+
Return the authenticated JWT payload. Raise a 401 (unauthorized) if
49+
absent or invalid.
50+
51+
``def auth_jwt_optionally_authenticated_payload() -> Payload | None``
52+
53+
Return the authenticated JWT payload, or ``None`` if the
54+
``Authorization`` header and cookie are absent. Raise a 401
55+
(unauthorized) if present and invalid.
56+
57+
``def auth_jwt_authenticated_partner() -> Partner``
58+
59+
Obtain the authenticated partner corresponding to the provided JWT
60+
token, according to the partner strategy defined on the ``auth_jwt``
61+
validator. Raise a 401 (unauthorized) if the partner could not be
62+
determined for any reason.
63+
64+
This is function suitable and intended to override
65+
``odoo.addons.fastapi.dependencies.authenticated_partner_impl``.
66+
67+
The partner record returned by this function is bound to an
68+
environment that uses the Odoo user obtained from the user strategy
69+
defined on the ``auth_jwt`` validator. When used
70+
``authenticated_partner_impl`` this in turn ensures that
71+
``odoo.addons.fastapi.dependencies.authenticated_partner_env`` is
72+
also bound to the correct Odoo user.
73+
74+
``def auth_jwt_optionally_authenticated_partner() -> Partner``
75+
76+
Same as ``auth_jwt_partner`` except it returns an empty recordset
77+
bound to the ``public`` user if the ``Authorization`` header and
78+
cookie are absent, or if the JWT validator could not find the partner
79+
and declares that the partner is not required.
80+
81+
``def auth_jwt_authenticated_odoo_env() -> Environment``
82+
83+
Return an Odoo environment using the the Odoo user obtained from the
84+
user strategy defined on the ``auth_jwt`` validator, if the request
85+
could be authenticated using a JWT validator. Raise a 401
86+
(unauthorized) otherwise.
87+
88+
This is function suitable and intended to override
89+
``odoo.addons.fastapi.dependencies.authenticated_odoo_env_impl``.
90+
91+
``def auth_jwt_default_validator_name() -> str | None``
92+
93+
Return the name of the default JWT validator to use.
94+
95+
The default implementation returns ``None`` meaning only one active
96+
JWT validator is allowed. This dependency is meant to be overridden.
97+
98+
``def auth_jwt_http_header_authorization() -> str | None``
99+
100+
By default, return the credentials part of the ``Authorization``
101+
header, or ``None`` if absent. This dependency is meant to be
102+
overridden, in particular with
103+
``fastapi.security.OAuth2AuthorizationCodeBearer`` to let swagger
104+
handle OAuth2 authorization (such override is only necessary for
105+
comfort when using the swagger interface).
106+
107+
Bug Tracker
108+
===========
109+
110+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
111+
In case of trouble, please check there if your issue has already been reported.
112+
If you spotted it first, help us to smash it by providing a detailed and welcomed
113+
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_auth_jwt%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
114+
115+
Do not contact contributors directly about support or help with technical issues.
116+
117+
Credits
118+
=======
119+
120+
Authors
121+
-------
122+
123+
* ACSONE SA/NV
124+
125+
Maintainers
126+
-----------
127+
128+
This module is maintained by the OCA.
129+
130+
.. image:: https://odoo-community.org/logo.png
131+
:alt: Odoo Community Association
132+
:target: https://odoo-community.org
133+
134+
OCA, or the Odoo Community Association, is a nonprofit organization whose
135+
mission is to support the collaborative development of Odoo features and
136+
promote its widespread use.
137+
138+
.. |maintainer-sbidoul| image:: https://github.com/sbidoul.png?size=40px
139+
:target: https://github.com/sbidoul
140+
:alt: sbidoul
141+
142+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
143+
144+
|maintainer-sbidoul|
145+
146+
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/fastapi_auth_jwt>`_ project on GitHub.
147+
148+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

fastapi_auth_jwt/__init__.py

Whitespace-only changes.

fastapi_auth_jwt/__manifest__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2023 ACSONE SA/NV
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
{
5+
"name": "FastAPI Auth JWT support",
6+
"summary": """
7+
JWT bearer token authentication for FastAPI.""",
8+
"version": "18.0.1.0.0",
9+
"license": "LGPL-3",
10+
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
11+
"maintainers": ["sbidoul"],
12+
"website": "https://github.com/OCA/rest-framework",
13+
"external_dependencies": {"python": ["pyjwt", "cryptography"]},
14+
"depends": [
15+
"fastapi",
16+
"auth_jwt",
17+
],
18+
"data": [],
19+
"demo": [],
20+
"installable": True,
21+
}

0 commit comments

Comments
 (0)