Skip to content

Commit

Permalink
Merge branch 'master' into umar/replace-jwkest-with-pyjwt
Browse files Browse the repository at this point in the history
  • Loading branch information
mumarkhan999 committed Mar 28, 2023
2 parents d5f6d2d + 14c2cd7 commit e13753d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions auth_backends/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import six
from Cryptodome.PublicKey import RSA
from django.core.cache import cache
from jwt.algorithms import get_default_algorithms
from social_core.tests.backends.oauth import OAuth2Test


Expand All @@ -25,6 +24,7 @@ class EdXOAuth2Tests(OAuth2Test):
def setUp(self):
cache.clear()
super().setUp()
self.key = RSA.generate(2048).export_key('PEM')

def set_social_auth_setting(self, setting_name, value):
"""
Expand Down Expand Up @@ -60,14 +60,13 @@ def create_jwt_access_token(self, expires_in=3600, issuer=None, key=None, alg='R
Arguments:
expires_in (int): Number of seconds after which the token expires.
issuer (str): Issuer of the token.
key (cryptography.hazmat.backends.openssl.rsa._RSAPrivateKey): Key used to sign the token.
key (bytes PEM-format): Key used to sign the token.
alg (str): Signing algorithm.
Returns:
str: JWT
"""
algorithm = get_default_algorithms()[alg]
key = key or algorithm.prepare_key(RSA.generate(2048).export_key('PEM'))
key = key or self.key
now = datetime.datetime.utcnow()
expiration_datetime = now + datetime.timedelta(seconds=expires_in)
issue_datetime = now
Expand Down

0 comments on commit e13753d

Please sign in to comment.