Skip to content

Commit 0e1ad1d

Browse files
[MIG] auth_jwt: Migration to 19.0
1 parent 9bacf24 commit 0e1ad1d

File tree

5 files changed

+47
-39
lines changed

5 files changed

+47
-39
lines changed

auth_jwt/README.rst

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Auth JWT
2121
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2222
:alt: License: LGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
24-
:target: https://github.com/OCA/server-auth/tree/18.0/auth_jwt
24+
:target: https://github.com/OCA/server-auth/tree/19.0/auth_jwt
2525
:alt: OCA/server-auth
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/server-auth-18-0/server-auth-18-0-auth_jwt
27+
:target: https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_jwt
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -52,24 +52,24 @@ Odoo controller routes.
5252

5353
To use it, you must:
5454

55-
- Create an ``auth.jwt.validator`` record to configure how the JWT token
56-
will be validated.
57-
- Add an ``auth="jwt_{validator-name}"`` or
58-
``auth="public_or_jwt_{validator-name}"`` attribute to the routes you
59-
want to protect where ``{validator-name}`` corresponds to the name
60-
attribute of the JWT validator record.
55+
- Create an ``auth.jwt.validator`` record to configure how the JWT
56+
token will be validated.
57+
- Add an ``auth="jwt_{validator-name}"`` or
58+
``auth="public_or_jwt_{validator-name}"`` attribute to the routes you
59+
want to protect where ``{validator-name}`` corresponds to the name
60+
attribute of the JWT validator record.
6161

6262
The ``auth_jwt_demo`` module provides examples.
6363

6464
The JWT validator can be configured with the following properties:
6565

66-
- ``name``: the validator name, to match the
67-
``auth="jwt_{validator-name}"`` route property.
68-
- ``audience``: a comma-separated list of allowed audiences, used to
69-
validate the ``aud`` claim.
70-
- ``issuer``: used to validate the ``iss`` claim.
71-
- Signature type (secret or public key), algorithm, secret and JWK URI
72-
are used to validate the token signature.
66+
- ``name``: the validator name, to match the
67+
``auth="jwt_{validator-name}"`` route property.
68+
- ``audience``: a comma-separated list of allowed audiences, used to
69+
validate the ``aud`` claim.
70+
- ``issuer``: used to validate the ``iss`` claim.
71+
- Signature type (secret or public key), algorithm, secret and JWK URI
72+
are used to validate the token signature.
7373

7474
In addition, the ``exp`` claim is validated to reject expired tokens.
7575

@@ -124,7 +124,7 @@ Bug Tracker
124124
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_.
125125
In case of trouble, please check there if your issue has already been reported.
126126
If you spotted it first, help us to smash it by providing a detailed and welcomed
127-
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_jwt%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
127+
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_jwt%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
128128

129129
Do not contact contributors directly about support or help with technical issues.
130130

@@ -139,8 +139,8 @@ Authors
139139
Contributors
140140
------------
141141

142-
- Stéphane Bidoul <stephane.bidoul@acsone.eu>
143-
- Mohamed Alkobrosli <malkobrosly@kencove.com>
142+
- Stéphane Bidoul <stephane.bidoul@acsone.eu>
143+
- Mohamed Alkobrosli <malkobrosly@kencove.com>
144144

145145
Maintainers
146146
-----------
@@ -163,6 +163,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
163163

164164
|maintainer-sbidoul|
165165

166-
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/18.0/auth_jwt>`_ project on GitHub.
166+
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/19.0/auth_jwt>`_ project on GitHub.
167167

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

auth_jwt/__manifest__.py

Lines changed: 1 addition & 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": "18.0.1.0.0",
8+
"version": "19.0.1.0.0",
99
"license": "LGPL-3",
1010
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
1111
"maintainers": ["sbidoul"],

auth_jwt/models/auth_jwt_validator.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from calendar import timegm
88
from functools import partial
99

10-
import jwt # pylint: disable=missing-manifest-dependency
10+
import jwt
1111
from jwt import PyJWKClient
1212
from werkzeug.exceptions import InternalServerError
1313

14-
from odoo import _, api, fields, models, tools
14+
from odoo import api, fields, models, tools
1515
from odoo.exceptions import ValidationError
1616

1717
from ..exceptions import (
@@ -98,16 +98,14 @@ class AuthJwtValidator(models.Model):
9898
default=True, help="Set to false only for development without https."
9999
)
100100

101-
_sql_constraints = [
102-
("name_uniq", "unique(name)", "JWT validator names must be unique !"),
103-
]
101+
models.Constraint("UNIQUE(name)", "JWT validator names must be unique !")
104102

105103
@api.constrains("name")
106104
def _check_name(self):
107105
for rec in self:
108106
if not rec.name.isidentifier():
109107
raise ValidationError(
110-
_("Name %r is not a valid python identifier.") % (rec.name,)
108+
self.env._("Name %r is not a valid python identifier.", rec.name)
111109
)
112110

113111
@api.constrains("next_validator_id")
@@ -121,8 +119,9 @@ def _check_next_validator_id(self):
121119
chain.append(validator.name)
122120
if rec == validator:
123121
raise ValidationError(
124-
_("Validators mustn't make a closed chain: {}.").format(
125-
" -> ".join(chain)
122+
self.env._(
123+
"Validators mustn't make a closed chain: %s.",
124+
" -> ".join(chain),
126125
)
127126
)
128127

@@ -131,11 +130,11 @@ def _check_cookie_name(self):
131130
for rec in self:
132131
if rec.cookie_enabled and not rec.cookie_name:
133132
raise ValidationError(
134-
_(
133+
self.env._(
135134
"A cookie name must be provided on JWT validator %s "
136-
"because it has cookie mode enabled."
135+
"because it has cookie mode enabled.",
136+
rec.name,
137137
)
138-
% (rec.name,)
139138
)
140139

141140
@api.model
@@ -246,7 +245,14 @@ def _get_and_check_partner_id(self, payload):
246245

247246
def _register_hook(self):
248247
res = super()._register_hook()
249-
self.search([])._register_auth_method()
248+
BATCH_SIZE = 100
249+
offset = 0
250+
while True:
251+
validators = self.search([], limit=BATCH_SIZE, offset=offset)
252+
if not validators:
253+
break
254+
validators._register_auth_method()
255+
offset += BATCH_SIZE
250256
return res
251257

252258
def _register_auth_method(self):

auth_jwt/static/description/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Auth JWT</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:0257cb75b9a02ab9b3f1aeebe8e0c5aee0b983f8b5ac1692132897dfb1986d02
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/server-auth/tree/18.0/auth_jwt"><img alt="OCA/server-auth" src="https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-auth-18-0/server-auth-18-0-auth_jwt"><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/server-auth&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/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-auth/tree/19.0/auth_jwt"><img alt="OCA/server-auth" src="https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_jwt"><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/server-auth&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>JWT bearer token authentication.</p>
379379
<p><strong>Table of contents</strong></p>
380380
<div class="contents local topic" id="contents">
@@ -400,8 +400,8 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
400400
Odoo controller routes.</p>
401401
<p>To use it, you must:</p>
402402
<ul class="simple">
403-
<li>Create an <tt class="docutils literal">auth.jwt.validator</tt> record to configure how the JWT token
404-
will be validated.</li>
403+
<li>Create an <tt class="docutils literal">auth.jwt.validator</tt> record to configure how the JWT
404+
token will be validated.</li>
405405
<li>Add an <tt class="docutils literal"><span class="pre">auth=&quot;jwt_{validator-name}&quot;</span></tt> or
406406
<tt class="docutils literal"><span class="pre">auth=&quot;public_or_jwt_{validator-name}&quot;</span></tt> attribute to the routes you
407407
want to protect where <tt class="docutils literal"><span class="pre">{validator-name}</span></tt> corresponds to the name
@@ -463,7 +463,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
463463
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-auth/issues">GitHub Issues</a>.
464464
In case of trouble, please check there if your issue has already been reported.
465465
If you spotted it first, help us to smash it by providing a detailed and welcomed
466-
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20auth_jwt%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
466+
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20auth_jwt%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
467467
<p>Do not contact contributors directly about support or help with technical issues.</p>
468468
</div>
469469
<div class="section" id="credits">
@@ -492,7 +492,7 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
492492
promote its widespread use.</p>
493493
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
494494
<p><a class="reference external image-reference" href="https://github.com/sbidoul"><img alt="sbidoul" src="https://github.com/sbidoul.png?size=40px" /></a></p>
495-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/18.0/auth_jwt">OCA/server-auth</a> project on GitHub.</p>
495+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/19.0/auth_jwt">OCA/server-auth</a> project on GitHub.</p>
496496
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
497497
</div>
498498
</div>

auth_jwt/tests/test_auth_jwt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ def test_invalid_validation_auto_chain(self):
264264
)
265265

266266
def test_partner_id_strategy_email_found(self):
267-
partner = self.env["res.partner"].search([("email", "!=", False)])[0]
267+
partner = self.env["res.partner"].create(
268+
{"name": "Test Partner Found", "email": "found@example.com"}
269+
)
268270
self._create_validator("validator6")
269271
authorization = "Bearer " + self._create_token(email=partner.email)
270272
with self._mock_request(authorization=authorization) as request:

0 commit comments

Comments
 (0)