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.
4343Usage
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
4949To 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
5758The ``auth_jwt_demo `` module provides examples.
5859
5960The 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
6970In addition, the ``exp `` claim is validated to reject expired tokens.
7071
7172If 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
9397The 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
111117Bug Tracker
112118===========
113119
114120Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues >`_.
115121In case of trouble, please check there if your issue has already been reported.
116122If 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
119125Do not contact contributors directly about support or help with technical issues.
120126
121127Credits
122128=======
123129
124130Authors
125- ~~~~~~~
131+ -------
126132
127133* ACSONE SA/NV
128134
129135Contributors
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
134141Maintainers
135- ~~~~~~~~~~~
142+ -----------
136143
137144This 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
157164You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
0 commit comments