Skip to content

Commit

Permalink
refactor: datetime.utcnow() is deprecated and scheduled for removal
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Sep 20, 2024
1 parent 7eda0e3 commit 7080853
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions allauth/socialaccount/providers/apple/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
import time
from urllib.parse import parse_qsl, quote, urlencode

from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -34,7 +34,7 @@ class AppleOAuth2Client(OAuth2Client):

def generate_client_secret(self):
"""Create a JWT signed with an apple provided private key"""
now = datetime.utcnow()
now = int(time.time())
app = get_adapter(self.request).get_app(self.request, "apple")
if not app.key:
raise ImproperlyConfigured("Apple 'key' missing")
Expand All @@ -46,7 +46,7 @@ def generate_client_secret(self):
"aud": "https://appleid.apple.com",
"sub": self.get_client_id(),
"iat": now,
"exp": now + timedelta(hours=1),
"exp": now + 60 * 60,
}
headers = {"kid": self.consumer_secret, "alg": "ES256"}
client_secret = jwt_encode(
Expand Down
6 changes: 3 additions & 3 deletions allauth/socialaccount/providers/apple/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from datetime import datetime, timedelta
import time
from importlib import import_module
from urllib.parse import parse_qs, urlparse

Expand Down Expand Up @@ -123,11 +123,11 @@ class AppleTests(OAuth2TestsMixin, TestCase):
provider_id = AppleProvider.id

def get_apple_id_token_payload(self):
now = datetime.utcnow()
now = int(time.time())
return {
"iss": "https://appleid.apple.com",
"aud": "app123id", # Matches `setup_app`
"exp": now + timedelta(hours=1),
"exp": now + 60 * 60,
"iat": now,
"sub": "000313.c9720f41e9434e18987a.1218",
"at_hash": "CkaUPjk4MJinaAq6Z0tGUA",
Expand Down
8 changes: 4 additions & 4 deletions allauth/socialaccount/providers/google/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from datetime import datetime, timedelta
import time
from importlib import import_module
from unittest.mock import Mock, patch

Expand Down Expand Up @@ -57,7 +57,7 @@ def get_expected_to_str(self):
return "[email protected]"

def get_google_id_token_payload(self):
now = datetime.utcnow()
now = int(time.time())
client_id = "app123id" # Matches `setup_app`
payload = {
"iss": "https://accounts.google.com",
Expand All @@ -74,7 +74,7 @@ def get_google_id_token_payload(self):
"family_name": "Penners",
"locale": "en",
"iat": now,
"exp": now + timedelta(hours=1),
"exp": now + 60 * 60,
}
payload.update(self.identity_overwrites)
return payload
Expand All @@ -97,7 +97,7 @@ def test_login(self):
def test_wrong_id_token_claim_values(self):
wrong_claim_values = {
"iss": "not-google",
"exp": datetime.utcnow() - timedelta(seconds=1),
"exp": time.time() - 1,
"aud": "foo",
}
for key, value in wrong_claim_values.items():
Expand Down

0 comments on commit 7080853

Please sign in to comment.