Skip to content

Commit 0254cfa

Browse files
Merge pull request #270 from supertokens/fix/cookie-expiry-format
fix: Django cookie expiry time format
2 parents bff80c0 + 52e78d6 commit 0254cfa

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## unreleased
99

10+
- Fix django cookie expiry time format to make it consistent with other frameworks
11+
1012
## [0.11.11] - 2022-12-26
1113

1214
- Updates dashboard version

supertokens_python/framework/django/django_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def set_cookie(
5151
key=key,
5252
value=value,
5353
expires=datetime.fromtimestamp(ceil(expires / 1000)).strftime(
54-
"%A, %B %d, %Y %H:%M:%S"
54+
"%a, %d %b %Y %H:%M:%S GMT"
5555
),
5656
path=path,
5757
domain=domain,

tests/Django/test_django.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from inspect import isawaitable
1717
from typing import Any, Dict, Union
1818

19+
from datetime import datetime
1920
from django.http import HttpRequest, HttpResponse, JsonResponse
2021
from django.test import RequestFactory, TestCase
2122
from supertokens_python import InputAppInfo, SupertokensConfig, init
@@ -252,6 +253,13 @@ async def test_login_handle(self):
252253
assert len(cookies["sIdRefreshToken"]["value"]) > 0
253254
assert len(cookies["sRefreshToken"]["value"]) > 0
254255

256+
try:
257+
datetime.strptime(
258+
cookies["sAccessToken"]["expires"], "%a, %d %b %Y %H:%M:%S GMT"
259+
)
260+
except ValueError:
261+
assert False, "cookies expiry time doesn't have the correct format"
262+
255263
my_middleware = middleware(handle_view)
256264
request = self.factory.get("/handle", {"user_id": "user_id"})
257265

0 commit comments

Comments
 (0)