Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "13.0.1.1.0",
"version": "13.0.1.1.1",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"maintainers": ["sbidoul"],
Expand Down
11 changes: 7 additions & 4 deletions auth_jwt/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ class IrHttpJwt(models.AbstractModel):
_inherit = "ir.http"

@classmethod
def _authenticate(cls, auth_method="user"):
def _authenticate(cls, endpoint):
"""Protect the _authenticate method.

This is to ensure that the _authenticate method is called
in the correct conditions to invoke _auth_method_jwt below.
When migrating, review this method carefully by reading the original
_authenticate method and make sure the conditions have not changed.
"""
auth_method = endpoint.routing["auth"]
if request._is_cors_preflight(endpoint):
auth_method = 'none'
if (
auth_method in ("jwt", "public_or_jwt")
or auth_method.startswith("jwt_")
Expand All @@ -47,10 +50,10 @@ def _authenticate(cls, auth_method="user"):
# because _authenticate will not call _auth_method_jwt a second time.
if request.uid and not hasattr(request, "jwt_payload"):
_logger.error(
"A route with auth='jwt' should not have a request.uid here."
'A route with auth="jwt" should not have a request.uid here.'
)
raise UnauthorizedSessionMismatch()
return super()._authenticate(auth_method)
return super()._authenticate(endpoint)

@classmethod
def _auth_method_jwt(cls, validator_name=None):
Expand Down Expand Up @@ -90,4 +93,4 @@ def _get_bearer_token(cls):
if not mo:
_logger.info("Malformed Authorization header.")
raise UnauthorizedMalformedAuthorizationHeader()
return mo.group(1)
return mo.group(1)
2 changes: 1 addition & 1 deletion auth_jwt_demo/tests/test_auth_jwt_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _get_token(self, aud=None, email=None):
if email:
payload["email"] = email
access_token = jwt.encode(
payload, key=validator.secret_key, algorithm=validator.secret_algorithm,
payload, key=validator.secret_key, algorithm=validator.secret_algorithm
)
return "Bearer " + access_token

Expand Down