Skip to content

Commit

Permalink
swap python-jose with pyjwt for jwt options
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Dec 23, 2024
1 parent 5fffa75 commit df8307a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Release 3.9.2
- Migrate from using `python-jose` with native-python cryptographic backend to the `pyjwt` package

# Release 3.9.1
- Fix a bug with SIP options in the `Opentok.dial` method

Expand Down
4 changes: 2 additions & 2 deletions opentok/opentok.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import platform # user-agent
from socket import inet_aton # create_session
import xml.dom.minidom as xmldom # create_session
from jose import jwt # _create_jwt_auth_header
from jwt import encode # _create_jwt_auth_header
import random # _create_jwt_auth_header
import logging # logging
import warnings # Native. Used for notifying deprecations
Expand Down Expand Up @@ -2065,7 +2065,7 @@ def _create_jwt_auth_header(self):
"jti": "{0}".format(0, random.random()),
}

return jwt.encode(payload, self.api_secret, algorithm="HS256")
return encode(payload, self.api_secret, algorithm="HS256")

def mute_all(
self, session_id: str, excludedStreamIds: Optional[List[str]]
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import codecs
import os
import re
import sys

here = os.path.abspath(os.path.dirname(__file__))


# Read the version number from a source file.
# Why read it, and not import?
# see https://groups.google.com/d/topic/pypa-dev/0PkjVpcxTzQ/discussion
Expand All @@ -27,7 +27,7 @@ def find_version(*file_paths):
with codecs.open("README.rst", encoding="utf-8") as f:
long_description = f.read()

install_requires = ["requests", "six", "pytz", "python-jose", "rsa>=4.7"]
install_requires = ["requests", "six", "pytz", "pyjwt[crypto]>=1.6.4", "rsa>=4.7"]

setup(
name="opentok",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_custom_jwt_claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from opentok import Client, __version__
import time
from jose import jwt
from jwt import decode


class JwtCustomClaimsTest(unittest.TestCase):
Expand All @@ -19,7 +19,7 @@ def setUp(self):
def test_livetime_custom_claim(self):
self.opentok.jwt_livetime = 5 # Token will expire 5 minutes in the future
jwt_token = self.opentok._create_jwt_auth_header()
claims = jwt.decode(jwt_token, self.api_secret, algorithms=[u("HS256")])
claims = decode(jwt_token, self.api_secret, algorithms=[u("HS256")])
expect(claims).to(have_key(u("exp")))
expect(int(claims[u("exp")])).to(
be_above(int(time.time()) + (60 * 4))
Expand Down
4 changes: 2 additions & 2 deletions tests/validate_jwt.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from six import u
from expects import *
from jose import jwt
from jwt import decode
import time


def validate_jwt_header(self, jsonwebtoken):
claims = jwt.decode(jsonwebtoken, self.api_secret, algorithms=[u("HS256")])
claims = decode(jsonwebtoken, self.api_secret, algorithms=[u("HS256")])
expect(claims).to(have_key(u("iss")))
expect(claims[u("iss")]).to(equal(self.api_key))
expect(claims).to(have_key(u("ist")))
Expand Down

0 comments on commit df8307a

Please sign in to comment.