Skip to content

Commit

Permalink
Fixes #76: fix possible "get multiple values" exception in jwt processor
Browse files Browse the repository at this point in the history
  • Loading branch information
dolamroth committed Feb 8, 2024
1 parent 1b9b59b commit b617fa7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions starlette_web/contrib/auth/jwt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,35 @@ def encode_jwt(
expires_in: int = None,
**kwargs,
) -> Tuple[str, datetime.datetime]:
_options = {**self.init_options}
_options.update(kwargs)

_expires_at = self._get_expires_at(
expires_in=expires_in,
**self.init_options,
**kwargs,
**_options,
)
_payload = copy.deepcopy(payload)
_payload["exp"] = _expires_at
self._enhance_payload_for_encode(
_payload,
**self.init_options,
**kwargs,
**_options,
)

token = jwt.encode(
payload=_payload,
key=self._get_encode_secret_key,
**self._get_encode_options(**self.init_options, **kwargs),
**self._get_encode_options(**_options),
)
return token, _expires_at

def decode_jwt(self, encoded_jwt: str, **kwargs):
_options = {**self.init_options}
_options.update(kwargs)

return jwt.decode(
encoded_jwt,
key=self._get_decode_secret_key,
**self._get_decode_options(**self.init_options, **kwargs),
**self._get_decode_options(**_options),
)

@cached_property
Expand Down

0 comments on commit b617fa7

Please sign in to comment.