Skip to content

Commit b1a63a2

Browse files
dnplkndllkobros-tech
authored andcommitted
[MIG] fastapi_auth_jwt: Migration to 18.0
1 parent 5083dbc commit b1a63a2

12 files changed

Lines changed: 167 additions & 138 deletions

File tree

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: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ FastAPI Auth JWT support
1717
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
1818
:alt: License: LGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
20-
:target: https://github.com/OCA/rest-framework/tree/16.0/fastapi_auth_jwt
20+
:target: https://github.com/OCA/rest-framework/tree/18.0/fastapi_auth_jwt
2121
:alt: OCA/rest-framework
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi_auth_jwt
23+
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-fastapi_auth_jwt
2424
:alt: Translate me on Weblate
2525
.. |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=16.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

31-
This module provides ``FastAPI`` ``Depends`` to allow authentication with `auth_jwt
32-
<https://github.com/OCA/server-auth/tree/16.0/auth_jwt>`_.
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>`__.
3334

3435
**Table of contents**
3536

@@ -39,83 +40,90 @@ This module provides ``FastAPI`` ``Depends`` to allow authentication with `auth_
3940
Usage
4041
=====
4142

42-
The following FastAPI dependencies are provided and importable from
43+
The following FastAPI dependencies are provided and importable from
4344
``odoo.addons.fastapi_auth_jwt.dependencies``:
4445

4546
``def auth_jwt_authenticated_payload() -> Payload``
4647

47-
Return the authenticated JWT payload. Raise a 401 (unauthorized) if absent or invalid.
48+
Return the authenticated JWT payload. Raise a 401 (unauthorized) if
49+
absent or invalid.
4850

4951
``def auth_jwt_optionally_authenticated_payload() -> Payload | None``
5052

51-
Return the authenticated JWT payload, or ``None`` if the ``Authorization`` header and
52-
cookie are absent. Raise a 401 (unauthorized) if present and invalid.
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.
5356

5457
``def auth_jwt_authenticated_partner() -> Partner``
5558

56-
Obtain the authenticated partner corresponding to the provided JWT token, according to
57-
the partner strategy defined on the ``auth_jwt`` validator. Raise a 401 (unauthorized)
58-
if the partner could not be determined for any reason.
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.
5963

60-
This is function suitable and intended to override
61-
``odoo.addons.fastapi.dependencies.authenticated_partner_impl``.
64+
This is function suitable and intended to override
65+
``odoo.addons.fastapi.dependencies.authenticated_partner_impl``.
6266

63-
The partner record returned by this function is bound to an environment that uses the
64-
Odoo user obtained from the user strategy defined on the ``auth_jwt`` validator. When
65-
used ``authenticated_partner_impl`` this in turn ensures that
66-
``odoo.addons.fastapi.dependencies.authenticated_partner_env`` is also bound to the
67-
correct Odoo user.
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.
6873

6974
``def auth_jwt_optionally_authenticated_partner() -> Partner``
7075

71-
Same as ``auth_jwt_partner`` except it returns an empty recordset bound to the
72-
``public`` user if the ``Authorization`` header and cookie are absent, or if the JWT
73-
validator could not find the partner and declares that the partner is not required.
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.
7480

7581
``def auth_jwt_authenticated_odoo_env() -> Environment``
7682

77-
Return an Odoo environment using the the Odoo user obtained from the user strategy
78-
defined on the ``auth_jwt`` validator, if the request could be authenticated using a
79-
JWT validator. Raise a 401 (unauthorized) otherwise.
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.
8087

81-
This is function suitable and intended to override
82-
``odoo.addons.fastapi.dependencies.authenticated_odoo_env_impl``.
88+
This is function suitable and intended to override
89+
``odoo.addons.fastapi.dependencies.authenticated_odoo_env_impl``.
8390

8491
``def auth_jwt_default_validator_name() -> str | None``
8592

86-
Return the name of the default JWT validator to use.
93+
Return the name of the default JWT validator to use.
8794

88-
The default implementation returns ``None`` meaning only one active JWT validator is
89-
allowed. This dependency is meant to be overridden.
95+
The default implementation returns ``None`` meaning only one active
96+
JWT validator is allowed. This dependency is meant to be overridden.
9097

9198
``def auth_jwt_http_header_authorization() -> str | None``
9299

93-
By default, return the credentials part of the ``Authorization`` header, or ``None``
94-
if absent. This dependency is meant to be overridden, in particular with
95-
``fastapi.security.OAuth2AuthorizationCodeBearer`` to let swagger handle OAuth2
96-
authorization (such override is only necessary for comfort when using the swagger
97-
interface).
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).
98106

99107
Bug Tracker
100108
===========
101109

102110
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
103111
In case of trouble, please check there if your issue has already been reported.
104112
If you spotted it first, help us to smash it by providing a detailed and welcomed
105-
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_auth_jwt%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
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**>`_.
106114

107115
Do not contact contributors directly about support or help with technical issues.
108116

109117
Credits
110118
=======
111119

112120
Authors
113-
~~~~~~~
121+
-------
114122

115123
* ACSONE SA/NV
116124

117125
Maintainers
118-
~~~~~~~~~~~
126+
-----------
119127

120128
This module is maintained by the OCA.
121129

@@ -135,6 +143,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
135143

136144
|maintainer-sbidoul|
137145

138-
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/16.0/fastapi_auth_jwt>`_ project on GitHub.
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.
139147

140148
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

fastapi_auth_jwt/__manifest__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
"name": "FastAPI Auth JWT support",
66
"summary": """
77
JWT bearer token authentication for FastAPI.""",
8-
"version": "16.0.1.0.1",
8+
"version": "18.0.1.0.0",
99
"license": "LGPL-3",
1010
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
1111
"maintainers": ["sbidoul"],
1212
"website": "https://github.com/OCA/rest-framework",
13+
"external_dependencies": {"python": ["pyjwt", "cryptography"]},
1314
"depends": [
1415
"fastapi",
1516
"auth_jwt",
1617
],
1718
"data": [],
1819
"demo": [],
19-
"installable": False,
20+
"installable": True,
2021
}

fastapi_auth_jwt/dependencies.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import logging
55
from typing import Annotated, Any
66

7+
from fastapi import Depends, HTTPException, Request, Response
8+
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
79
from starlette.status import HTTP_401_UNAUTHORIZED
810

911
from odoo.api import Environment
@@ -19,9 +21,6 @@
1921
from odoo.addons.base.models.res_partner import Partner
2022
from odoo.addons.fastapi.dependencies import odoo_env
2123

22-
from fastapi import Depends, HTTPException, Request, Response
23-
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
24-
2524
_logger = logging.getLogger(__name__)
2625

2726

fastapi_auth_jwt/i18n/fastapi_auth_jwt.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
msgid ""
55
msgstr ""
6-
"Project-Id-Version: Odoo Server 16.0\n"
6+
"Project-Id-Version: Odoo Server 18.0\n"
77
"Report-Msgid-Bugs-To: \n"
88
"Last-Translator: \n"
99
"Language-Team: \n"

fastapi_auth_jwt/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This module provides `FastAPI` `Depends` to allow authentication with
2+
[auth_jwt](https://github.com/OCA/server-auth/tree/18.0/auth_jwt).

fastapi_auth_jwt/readme/DESCRIPTION.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

fastapi_auth_jwt/readme/USAGE.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
The following FastAPI dependencies are provided and importable from
2+
`odoo.addons.fastapi_auth_jwt.dependencies`:
3+
4+
`def auth_jwt_authenticated_payload() -> Payload`
5+
6+
> Return the authenticated JWT payload. Raise a 401 (unauthorized) if
7+
> absent or invalid.
8+
9+
`def auth_jwt_optionally_authenticated_payload() -> Payload | None`
10+
11+
> Return the authenticated JWT payload, or `None` if the `Authorization`
12+
> header and cookie are absent. Raise a 401 (unauthorized) if present
13+
> and invalid.
14+
15+
`def auth_jwt_authenticated_partner() -> Partner`
16+
17+
> Obtain the authenticated partner corresponding to the provided JWT
18+
> token, according to the partner strategy defined on the `auth_jwt`
19+
> validator. Raise a 401 (unauthorized) if the partner could not be
20+
> determined for any reason.
21+
>
22+
> This is function suitable and intended to override
23+
> `odoo.addons.fastapi.dependencies.authenticated_partner_impl`.
24+
>
25+
> The partner record returned by this function is bound to an
26+
> environment that uses the Odoo user obtained from the user strategy
27+
> defined on the `auth_jwt` validator. When used
28+
> `authenticated_partner_impl` this in turn ensures that
29+
> `odoo.addons.fastapi.dependencies.authenticated_partner_env` is also
30+
> bound to the correct Odoo user.
31+
32+
`def auth_jwt_optionally_authenticated_partner() -> Partner`
33+
34+
> Same as `auth_jwt_partner` except it returns an empty recordset bound
35+
> to the `public` user if the `Authorization` header and cookie are
36+
> absent, or if the JWT validator could not find the partner and
37+
> declares that the partner is not required.
38+
39+
`def auth_jwt_authenticated_odoo_env() -> Environment`
40+
41+
> Return an Odoo environment using the the Odoo user obtained from the
42+
> user strategy defined on the `auth_jwt` validator, if the request
43+
> could be authenticated using a JWT validator. Raise a 401
44+
> (unauthorized) otherwise.
45+
>
46+
> This is function suitable and intended to override
47+
> `odoo.addons.fastapi.dependencies.authenticated_odoo_env_impl`.
48+
49+
`def auth_jwt_default_validator_name() -> str | None`
50+
51+
> Return the name of the default JWT validator to use.
52+
>
53+
> The default implementation returns `None` meaning only one active JWT
54+
> validator is allowed. This dependency is meant to be overridden.
55+
56+
`def auth_jwt_http_header_authorization() -> str | None`
57+
58+
> By default, return the credentials part of the `Authorization` header,
59+
> or `None` if absent. This dependency is meant to be overridden, in
60+
> particular with `fastapi.security.OAuth2AuthorizationCodeBearer` to
61+
> let swagger handle OAuth2 authorization (such override is only
62+
> necessary for comfort when using the swagger interface).

fastapi_auth_jwt/readme/USAGE.rst

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)