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 docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Token expiration
JWT_EXPIRATION_DELTA
~~~~~~~~~~~~~~~~~~~~

Timedelta added to *utcnow()* to set the expiration time
Timedelta added to *now(tz=timezone.utc)* to set the expiration time

Default: ``timedelta(minutes=5)``

Expand Down
6 changes: 3 additions & 3 deletions graphql_jwt/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from calendar import timegm
from datetime import datetime
from datetime import datetime,timezone
from functools import wraps

from django.contrib.auth import authenticate, get_user_model
Expand Down Expand Up @@ -119,7 +119,7 @@ def refresh_expiration(f):
def wrapper(cls, *args, **kwargs):
def on_resolve(payload):
payload.refresh_expires_in = (
timegm(datetime.utcnow().utctimetuple())
timegm(datetime.now(tz=timezone.utc).utctimetuple())
+ jwt_settings.JWT_REFRESH_EXPIRATION_DELTA.total_seconds()
)
return payload
Expand Down Expand Up @@ -161,7 +161,7 @@ def wrapped_view(request, *args, **kwargs):
response = view_func(request, *args, **kwargs)

if hasattr(request, "jwt_token"):
expires = datetime.utcnow() + jwt_settings.JWT_EXPIRATION_DELTA
expires = datetime.now(tz=timezone.utc) + jwt_settings.JWT_EXPIRATION_DELTA

set_cookie(
response,
Expand Down
Binary file added graphql_jwt/locale/cs/LC_MESSAGES/django.mo
Binary file not shown.
59 changes: 59 additions & 0 deletions graphql_jwt/locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# Josef Havránek <9963200+07pepa@users.noreply.github.com, 2025.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-04-22 08:01+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=(n == 1 && n % 1 == 0) ? 0 : (n >= 2 && n "
"<= 4 && n % 1 == 0) ? 1: (n % 1 != 0 ) ? 2 : 3;\n"
#: graphql_jwt/decorators.py:104
msgid "Please enter valid credentials"
msgstr "Prosím zadejte platné přihlašovací údaje"

#: graphql_jwt/decorators.py:203
msgid "Token is required"
msgstr "Token je vyžadován"

#: graphql_jwt/exceptions.py:15
msgid "You do not have permission to perform this action"
msgstr "Nemáte oprávnění k provedení této akce"

#: graphql_jwt/exceptions.py:19
msgid "Signature has expired"
msgstr "Podpis vypršel"

#: graphql_jwt/mixins.py:78
msgid "origIat field is required"
msgstr "origIat pole je vyžadováno"

#: graphql_jwt/mixins.py:81
msgid "Refresh has expired"
msgstr "Obnovení vypršelo"

#: graphql_jwt/utils.py:93
msgid "Error decoding signature"
msgstr "Chyba při dekódování podpisu"

#: graphql_jwt/utils.py:95
msgid "Invalid token"
msgstr "Neplatný token"

#: graphql_jwt/utils.py:111
msgid "Invalid payload"
msgstr "Neplatná data"

#: graphql_jwt/utils.py:116
msgid "User is disabled"
msgstr "Uživatel je vypnutý"
8 changes: 4 additions & 4 deletions graphql_jwt/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from calendar import timegm
from datetime import datetime
from datetime import datetime,timezone

import django
from django.contrib.auth import get_user_model
Expand All @@ -17,15 +17,15 @@ def jwt_payload(user, context=None):
if hasattr(username, "pk"):
username = username.pk

exp = datetime.utcnow() + jwt_settings.JWT_EXPIRATION_DELTA
exp = datetime.now(tz=timezone.utc) + jwt_settings.JWT_EXPIRATION_DELTA

payload = {
user.USERNAME_FIELD: username,
"exp": timegm(exp.utctimetuple()),
}

if jwt_settings.JWT_ALLOW_REFRESH:
payload["origIat"] = timegm(datetime.utcnow().utctimetuple())
payload["origIat"] = timegm(datetime.now(tz=timezone.utc).utctimetuple())

if jwt_settings.JWT_AUDIENCE is not None:
payload["aud"] = jwt_settings.JWT_AUDIENCE
Expand Down Expand Up @@ -119,7 +119,7 @@ def get_user_by_payload(payload):

def refresh_has_expired(orig_iat, context=None):
exp = orig_iat + jwt_settings.JWT_REFRESH_EXPIRATION_DELTA.total_seconds()
return timegm(datetime.utcnow().utctimetuple()) > exp
return timegm(datetime.now(tz=timezone.utc).utctimetuple()) > exp


def set_cookie(response, key, value, expires):
Expand Down
4 changes: 2 additions & 2 deletions tests/context_managers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from contextlib import contextmanager
from datetime import datetime, timedelta
from datetime import datetime, timedelta,timezone
from unittest import mock

from graphql_jwt.settings import jwt_settings
Expand All @@ -16,7 +16,7 @@ def catch_signal(signal):
@contextmanager
def back_to_the_future(**kwargs):
with mock.patch("graphql_jwt.utils.datetime") as datetime_mock:
datetime_mock.utcnow.return_value = datetime.utcnow() + timedelta(**kwargs)
datetime_mock.now.return_value = datetime.now(tz=timezone.utc) + timedelta(**kwargs)
yield datetime_mock


Expand Down