Skip to content

Commit 4e6e5ca

Browse files
MikeAelbrechtdnplkndll
authored andcommitted
[MIG] auth_jwt: Migration to 17.0
1 parent a63308d commit 4e6e5ca

18 files changed

Lines changed: 240 additions & 220 deletions

auth_jwt/README.rst

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Auth JWT
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:d22309ac82ef1eb8879974683b10d4be288eb330fd7e250927f1a8d602dc3988
10+
!! source digest: sha256:608e8780fabb7f7a32193245dd2a7e594810863dcc55aa1dc9e5b2bc3426d74c
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -17,13 +17,13 @@ Auth JWT
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%2Fserver--auth-lightgray.png?logo=github
20-
:target: https://github.com/OCA/server-auth/tree/16.0/auth_jwt
20+
:target: https://github.com/OCA/server-auth/tree/17.0/auth_jwt
2121
:alt: OCA/server-auth
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/server-auth-16-0/server-auth-16-0-auth_jwt
23+
:target: https://translation.odoo-community.org/projects/server-auth-17-0/server-auth-17-0-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/server-auth&target_branch=16.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=17.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -43,96 +43,103 @@ This module requires the ``pyjwt`` library to be installed.
4343
Usage
4444
=====
4545

46-
This module lets developpers add a new ``jwt`` authentication method on Odoo
47-
controller routes.
46+
This module lets developpers add a new ``jwt`` authentication method on
47+
Odoo controller routes.
4848

4949
To use it, you must:
5050

51-
* Create an ``auth.jwt.validator`` record to configure how the JWT token will
52-
be validated.
53-
* Add an ``auth="jwt_{validator-name}"`` or ``auth="public_or_jwt_{validator-name}"``
54-
attribute to the routes you want to protect where ``{validator-name}`` corresponds to
55-
the name attribute of the JWT validator record.
51+
- Create an ``auth.jwt.validator`` record to configure how the JWT token
52+
will be validated.
53+
- Add an ``auth="jwt_{validator-name}"`` or
54+
``auth="public_or_jwt_{validator-name}"`` attribute to the routes you
55+
want to protect where ``{validator-name}`` corresponds to the name
56+
attribute of the JWT validator record.
5657

5758
The ``auth_jwt_demo`` module provides examples.
5859

5960
The JWT validator can be configured with the following properties:
6061

61-
* ``name``: the validator name, to match the ``auth="jwt_{validator-name}"``
62-
route property.
63-
* ``audience``: a comma-separated list of allowed audiences, used to validate
64-
the ``aud`` claim.
65-
* ``issuer``: used to validate the ``iss`` claim.
66-
* Signature type (secret or public key), algorithm, secret and JWK URI
62+
- ``name``: the validator name, to match the
63+
``auth="jwt_{validator-name}"`` route property.
64+
- ``audience``: a comma-separated list of allowed audiences, used to
65+
validate the ``aud`` claim.
66+
- ``issuer``: used to validate the ``iss`` claim.
67+
- Signature type (secret or public key), algorithm, secret and JWK URI
6768
are used to validate the token signature.
6869

6970
In addition, the ``exp`` claim is validated to reject expired tokens.
7071

7172
If the ``Authorization`` HTTP header is missing, malformed, or contains
72-
an invalid token, the request is rejected with a 401 (Unauthorized) code,
73-
unless the cookie mode is enabled (see below).
74-
75-
If the token is valid, the request executes with the configured user id. By
76-
default the user id selection strategy is ``static`` (i.e. the same for all
77-
requests) and the selected user is configured on the JWT validator. Additional
78-
strategies can be provided by overriding the ``_get_uid()`` method and
79-
extending the ``user_id_strategy`` selection field.
80-
81-
The selected user is *not* stored in the session. It is only available in
82-
``request.uid`` (and thus it is the one used in ``request.env``). To avoid any
83-
confusion and mismatches between the bearer token and the session, this module
84-
rejects requests made with an authenticated user session.
85-
86-
Additionally, if a ``partner_id_strategy`` is configured, a partner is searched
87-
and if found, its id is stored in the ``request.jwt_partner_id`` attribute. If
88-
``partner_id_required`` is set, a 401 (Unauthorized) is returned if no partner
89-
was found. Otherwise ``request.jwt_partner_id`` is left falsy. Additional
90-
strategies can be provided by overriding the ``_get_partner_id()`` method
91-
and extending the ``partner_id_strategy`` selection field.
73+
an invalid token, the request is rejected with a 401 (Unauthorized)
74+
code, unless the cookie mode is enabled (see below).
75+
76+
If the token is valid, the request executes with the configured user id.
77+
By default the user id selection strategy is ``static`` (i.e. the same
78+
for all requests) and the selected user is configured on the JWT
79+
validator. Additional strategies can be provided by overriding the
80+
``_get_uid()`` method and extending the ``user_id_strategy`` selection
81+
field.
82+
83+
The selected user is *not* stored in the session. It is only available
84+
in ``request.uid`` (and thus it is the one used in ``request.env``). To
85+
avoid any confusion and mismatches between the bearer token and the
86+
session, this module rejects requests made with an authenticated user
87+
session.
88+
89+
Additionally, if a ``partner_id_strategy`` is configured, a partner is
90+
searched and if found, its id is stored in the
91+
``request.jwt_partner_id`` attribute. If ``partner_id_required`` is set,
92+
a 401 (Unauthorized) is returned if no partner was found. Otherwise
93+
``request.jwt_partner_id`` is left falsy. Additional strategies can be
94+
provided by overriding the ``_get_partner_id()`` method and extending
95+
the ``partner_id_strategy`` selection field.
9296

9397
The decoded JWT payload is stored in ``request.jwt_payload``.
9498

95-
The ``public_auth_jwt`` method delegates authentication to the standard Odoo ``public``
96-
method when the Authorization header is not set. If it is set, the regular JWT
97-
authentication is performed as described above. This method is useful for public
98-
endpoints that need to work for anonymous users, but can be enhanced when an
99-
authenticated user is know. A typical use case is a "add to cart" endpoint that can work
100-
for anonymous users, but can be enhanced by binding the cart to a known customer when
101-
the authenticated user is known.
102-
103-
You can enable a cookie mode on JWT validators. In this case, the JWT payload obtained
104-
from the ``Authorization`` header is returned as a Http-Only cookie. This mode is
105-
sometimes simpler for front-end applications which do not then need to store and protect
106-
the JWT token across requests and can simply rely on the cookie management mechanisms of
107-
browsers. When both the ``Authorization`` header and a cookie are provided, the cookie
108-
is ignored in order to let clients authenticate with a different user by providing a new
109-
JWT token.
99+
The ``public_auth_jwt`` method delegates authentication to the standard
100+
Odoo ``public`` method when the Authorization header is not set. If it
101+
is set, the regular JWT authentication is performed as described above.
102+
This method is useful for public endpoints that need to work for
103+
anonymous users, but can be enhanced when an authenticated user is know.
104+
A typical use case is a "add to cart" endpoint that can work for
105+
anonymous users, but can be enhanced by binding the cart to a known
106+
customer when the authenticated user is known.
107+
108+
You can enable a cookie mode on JWT validators. In this case, the JWT
109+
payload obtained from the ``Authorization`` header is returned as a
110+
Http-Only cookie. This mode is sometimes simpler for front-end
111+
applications which do not then need to store and protect the JWT token
112+
across requests and can simply rely on the cookie management mechanisms
113+
of browsers. When both the ``Authorization`` header and a cookie are
114+
provided, the cookie is ignored in order to let clients authenticate
115+
with a different user by providing a new JWT token.
110116

111117
Bug Tracker
112118
===========
113119

114120
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_.
115121
In case of trouble, please check there if your issue has already been reported.
116122
If you spotted it first, help us to smash it by providing a detailed and welcomed
117-
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_jwt%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
123+
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_jwt%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
118124

119125
Do not contact contributors directly about support or help with technical issues.
120126

121127
Credits
122128
=======
123129

124130
Authors
125-
~~~~~~~
131+
-------
126132

127133
* ACSONE SA/NV
128134

129135
Contributors
130-
~~~~~~~~~~~~
136+
------------
131137

132-
* Stéphane Bidoul <stephane.bidoul@acsone.eu>
138+
- Stéphane Bidoul <stephane.bidoul@acsone.eu>
139+
- Mohamed Alkobrosli <malkobrosly@kencove.com>
133140

134141
Maintainers
135-
~~~~~~~~~~~
142+
-----------
136143

137144
This module is maintained by the OCA.
138145

@@ -152,6 +159,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
152159

153160
|maintainer-sbidoul|
154161

155-
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/16.0/auth_jwt>`_ project on GitHub.
162+
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/17.0/auth_jwt>`_ project on GitHub.
156163

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

auth_jwt/__manifest__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Auth JWT",
66
"summary": """
77
JWT bearer token authentication.""",
8-
"version": "16.0.1.1.0",
8+
"version": "17.0.1.0.0",
99
"license": "LGPL-3",
1010
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
1111
"maintainers": ["sbidoul"],
@@ -14,4 +14,7 @@
1414
"external_dependencies": {"python": ["pyjwt", "cryptography"]},
1515
"data": ["security/ir.model.access.csv", "views/auth_jwt_validator_views.xml"],
1616
"demo": [],
17+
"installable": True,
18+
"application": False,
19+
"auto_install": False,
1720
}

auth_jwt/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, errors):
4444
super().__init__(
4545
"Multiple errors occurred during JWT chain validation:\n"
4646
+ "\n".join(
47-
"{}: {}".format(validator_name, error)
47+
f"{validator_name}: {error}"
4848
for validator_name, error in self.errors.items()
4949
)
5050
)

auth_jwt/i18n/auth_jwt.pot

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
msgid ""
66
msgstr ""
7-
"Project-Id-Version: Odoo Server 16.0\n"
7+
"Project-Id-Version: Odoo Server 17.0\n"
88
"Report-Msgid-Bugs-To: \n"
99
"Last-Translator: \n"
1010
"Language-Team: \n"
@@ -176,11 +176,6 @@ msgstr ""
176176
msgid "Key"
177177
msgstr ""
178178

179-
#. module: auth_jwt
180-
#: model:ir.model.fields,field_description:auth_jwt.field_auth_jwt_validator____last_update
181-
msgid "Last Modified on"
182-
msgstr ""
183-
184179
#. module: auth_jwt
185180
#: model:ir.model.fields,field_description:auth_jwt.field_auth_jwt_validator__write_uid
186181
msgid "Last Updated by"

auth_jwt/i18n/es.po

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ msgstr "¡Los nombres de los validadores JWT deben ser únicos!"
187187
msgid "Key"
188188
msgstr "Clave"
189189

190-
#. module: auth_jwt
191-
#: model:ir.model.fields,field_description:auth_jwt.field_auth_jwt_validator____last_update
192-
msgid "Last Modified on"
193-
msgstr "Última Modificación el"
194-
195190
#. module: auth_jwt
196191
#: model:ir.model.fields,field_description:auth_jwt.field_auth_jwt_validator__write_uid
197192
msgid "Last Updated by"
@@ -355,3 +350,6 @@ msgstr "Los validadores no deben hacer una cadena cerrada: {}."
355350
#: model_terms:ir.ui.view,arch_db:auth_jwt.view_auth_jwt_validator_form
356351
msgid "arch"
357352
msgstr "arch"
353+
354+
#~ msgid "Last Modified on"
355+
#~ msgstr "Última Modificación el"

auth_jwt/i18n/it.po

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,6 @@ msgstr "I nomi dei validatori JWT devono essere univoci!"
184184
msgid "Key"
185185
msgstr "Chiave"
186186

187-
#. module: auth_jwt
188-
#: model:ir.model.fields,field_description:auth_jwt.field_auth_jwt_validator____last_update
189-
msgid "Last Modified on"
190-
msgstr "Ultima modifica il"
191-
192187
#. module: auth_jwt
193188
#: model:ir.model.fields,field_description:auth_jwt.field_auth_jwt_validator__write_uid
194189
msgid "Last Updated by"
@@ -352,3 +347,6 @@ msgstr "I validatori non devono creare una catena chiusa: {}."
352347
#: model_terms:ir.ui.view,arch_db:auth_jwt.view_auth_jwt_validator_form
353348
msgid "arch"
354349
msgstr "arch"
350+
351+
#~ msgid "Last Modified on"
352+
#~ msgstr "Ultima modifica il"

auth_jwt/models/ir_http.py

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

2020

2121
class IrHttpJwt(models.AbstractModel):
22-
2322
_inherit = "ir.http"
2423

2524
@classmethod

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"

auth_jwt/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Stéphane Bidoul \<<stephane.bidoul@acsone.eu>\>
2+
- Mohamed Alkobrosli \<<malkobrosly@kencove.com>\>

auth_jwt/readme/CONTRIBUTORS.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)