Skip to content

Commit

Permalink
[MIG] auth_jwt from 14 to 16
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jun 7, 2023
1 parent 7529708 commit c2d4b4e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion auth_jwt/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Auth JWT",
"summary": """
JWT bearer token authentication.""",
"version": "14.0.2.0.0",
"version": "16.0.1.0.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"maintainers": ["sbidoul"],
Expand Down
6 changes: 3 additions & 3 deletions auth_jwt/models/auth_jwt_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _decode(self, token):
header = jwt.get_unverified_header(token)
except Exception as e:
_logger.info("Invalid token: %s", e)
raise UnauthorizedInvalidToken()
raise UnauthorizedInvalidToken() from e
key = self._get_key(header.get("kid"))
algorithm = self.public_key_algorithm
try:
Expand All @@ -155,7 +155,7 @@ def _decode(self, token):
)
except Exception as e:
_logger.info("Invalid token: %s", e)
raise UnauthorizedInvalidToken()
raise UnauthorizedInvalidToken() from e
return payload

def _get_uid(self, payload):
Expand Down Expand Up @@ -216,7 +216,7 @@ def _unregister_auth_method(self):
try:
delattr(IrHttp.__class__, f"_auth_method_jwt_{rec.name}")
delattr(IrHttp.__class__, f"_auth_method_public_or_jwt_{rec.name}")
except AttributeError:
except AttributeError: # pylint: disable=except-pass
pass

@api.model_create_multi
Expand Down
2 changes: 1 addition & 1 deletion auth_jwt/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _auth_method_jwt(cls, validator_name=None):
uid = validator._get_and_check_uid(payload)
assert uid
partner_id = validator._get_and_check_partner_id(payload)
request.uid = uid # this resets request.env
request.update_env(user=uid)
request.jwt_payload = payload
request.jwt_partner_id = partner_id

Expand Down
6 changes: 4 additions & 2 deletions auth_jwt/tests/test_auth_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_user_id_strategy(self):
authorization = "Bearer " + self._create_token()
with self._mock_request(authorization=authorization) as request:
self.env["ir.http"]._auth_method_jwt_validator5()
self.assertEqual(request.uid, validator.static_user_id.id)
self.assertEqual(request.env.uid, validator.static_user_id.id)

def test_partner_id_strategy_email_found(self):
partner = self.env["res.partner"].search([("email", "!=", False)])[0]
Expand Down Expand Up @@ -399,7 +399,9 @@ def test_name_check(self):
def test_public_or_jwt_no_token(self):
with self._mock_request(authorization=None) as request:
self.env["ir.http"]._auth_method_public_or_jwt()
assert request.uid == self.env.ref("base.public_user").id
request.update_env.assert_called_once_with(
user=self.env.ref("base.public_user").id
)
assert not hasattr(request, "jwt_payload")

def test_public_or_jwt_valid_token(self):
Expand Down
2 changes: 1 addition & 1 deletion auth_jwt/views/auth_jwt_validator_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<field name="name">auth.jwt.validator.tree</field>
<field name="model">auth.jwt.validator</field>
<field name="arch" type="xml">
<tree string="arch">
<tree>
<field name="name" />
<field name="issuer" />
<field name="audience" />
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# generated from manifests external_dependencies
cryptography
pyjwt
pysaml2
python-jose
python-ldap
1 change: 1 addition & 0 deletions setup/auth_jwt/odoo/addons/auth_jwt
6 changes: 6 additions & 0 deletions setup/auth_jwt/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit c2d4b4e

Please sign in to comment.