Skip to content

Commit 5341851

Browse files
committed
TIMEOUT -> MAX_AGE
1 parent eb9ed59 commit 5341851

File tree

7 files changed

+27
-28
lines changed

7 files changed

+27
-28
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Don't forget to remove deprecated code on each major release!
2323

2424
- User login/logout features!
2525
- `reactpy_django.hooks.use_auth` to provide **persistent** `login` and `logout` functionality to your components.
26-
- `settings.py:REACTPY_AUTH_TOKEN_TIMEOUT` to control the maximum seconds before ReactPy no longer allows the browser to obtain a persistent login cookie.
26+
- `settings.py:REACTPY_AUTH_TOKEN_MAX_AGE` to control the maximum seconds before ReactPy's login token expires.
2727
- `settings.py:REACTPY_CLEAN_AUTH_TOKENS` to control whether ReactPy should clean up expired authentication tokens during automatic cleanups.
2828
- Automatically convert Django forms to ReactPy forms via the new `reactpy_django.components.django_form` component!
2929
- The ReactPy component tree can now be forcibly re-rendered via the new `reactpy_django.hooks.use_rerender` hook.

docs/src/reference/settings.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ Dotted path to the Django authentication backend to use for ReactPy components.
7373

7474
---
7575

76-
### `#!python REACTPY_AUTH_TOKEN_TIMEOUT`
76+
### `#!python REACTPY_AUTH_TOKEN_MAX_AGE`
7777

7878
**Default:** `#!python 30`
7979

8080
**Example Value(s):** `#!python 5`
8181

82-
Maximum seconds before ReactPy no longer allows the browser to obtain a login cookie.
82+
Maximum seconds before ReactPy's login token expires.
8383

84-
This setting exists because Django's authentication design require cookies to retain login status. ReactPy is rendered via WebSockets, and browsers do not allow active WebSocket connections to modify cookies.
84+
This setting exists because Django's authentication design requires cookies to retain login status. ReactPy is rendered via WebSockets, and browsers do not allow active WebSocket connections to modify cookies.
8585

8686
To work around this limitation, this setting provides a maximum validity period of a temporary login token. When `#!python reactpy_django.hooks.use_auth().login()` is called within your application, ReactPy will automatically create this temporary login token and command the browser to fetch it via HTTP.
8787

src/reactpy_django/auth/components.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ async def synchronize_auth_watchdog():
6363
This effect will automatically be cancelled if the session is successfully
6464
synchronized (via effect dependencies)."""
6565
if sync_needed:
66-
await asyncio.sleep(config.REACTPY_AUTH_TOKEN_TIMEOUT + 0.1)
66+
await asyncio.sleep(config.REACTPY_AUTH_TOKEN_MAX_AGE + 0.1)
6767
await asyncio.to_thread(
6868
_logger.warning,
69-
f"Client did not switch authentication sessions within {config.REACTPY_AUTH_TOKEN_TIMEOUT} (REACTPY_AUTH_TOKEN_TIMEOUT) seconds.",
69+
f"Client did not switch authentication sessions within {config.REACTPY_AUTH_TOKEN_MAX_AGE} (REACTPY_AUTH_TOKEN_MAX_AGE) seconds.",
7070
)
7171
set_sync_needed(False)
7272

src/reactpy_django/checks.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,23 @@ def reactpy_warnings(app_configs, **kwargs):
230230
)
231231
)
232232

233-
# Check if REACTPY_AUTH_TOKEN_TIMEOUT is a large value
234-
auth_token_timeout = config.REACTPY_AUTH_TOKEN_TIMEOUT
233+
# Check if REACTPY_AUTH_TOKEN_MAX_AGE is a large value
234+
auth_token_timeout = config.REACTPY_AUTH_TOKEN_MAX_AGE
235235
if isinstance(auth_token_timeout, int) and auth_token_timeout > 120:
236236
warnings.append(
237237
Warning(
238-
"REACTPY_AUTH_TOKEN_TIMEOUT is set to a very large value.",
239-
hint="It is suggested to keep REACTPY_AUTH_TOKEN_TIMEOUT under 120 seconds to prevent security risks.",
238+
"REACTPY_AUTH_TOKEN_MAX_AGE is set to a very large value.",
239+
hint="It is suggested to keep REACTPY_AUTH_TOKEN_MAX_AGE under 120 seconds to prevent security risks.",
240240
id="reactpy_django.W020",
241241
)
242242
)
243243

244-
# Check if REACTPY_AUTH_TOKEN_TIMEOUT is a small value
244+
# Check if REACTPY_AUTH_TOKEN_MAX_AGE is a small value
245245
if isinstance(auth_token_timeout, int) and auth_token_timeout <= 2:
246246
warnings.append(
247247
Warning(
248-
"REACTPY_AUTH_TOKEN_TIMEOUT is set to a very low value.",
249-
hint="It is suggested to keep REACTPY_AUTH_TOKEN_TIMEOUT above 2 seconds to account for client and server latency.",
248+
"REACTPY_AUTH_TOKEN_MAX_AGE is set to a very low value.",
249+
hint="It is suggested to keep REACTPY_AUTH_TOKEN_MAX_AGE above 2 seconds to account for client and server latency.",
250250
id="reactpy_django.W021",
251251
)
252252
)
@@ -544,22 +544,22 @@ def reactpy_errors(app_configs, **kwargs):
544544
)
545545
)
546546

547-
# Check if REACTPY_AUTH_TOKEN_TIMEOUT is a valid data type
548-
if not isinstance(config.REACTPY_AUTH_TOKEN_TIMEOUT, int):
547+
# Check if REACTPY_AUTH_TOKEN_MAX_AGE is a valid data type
548+
if not isinstance(config.REACTPY_AUTH_TOKEN_MAX_AGE, int):
549549
errors.append(
550550
Error(
551-
"Invalid type for REACTPY_AUTH_TOKEN_TIMEOUT.",
552-
hint="REACTPY_AUTH_TOKEN_TIMEOUT should be an integer.",
551+
"Invalid type for REACTPY_AUTH_TOKEN_MAX_AGE.",
552+
hint="REACTPY_AUTH_TOKEN_MAX_AGE should be an integer.",
553553
id="reactpy_django.E028",
554554
)
555555
)
556556

557-
# Check if REACTPY_AUTH_TOKEN_TIMEOUT is a positive integer
558-
if isinstance(config.REACTPY_AUTH_TOKEN_TIMEOUT, int) and config.REACTPY_AUTH_TOKEN_TIMEOUT < 0:
557+
# Check if REACTPY_AUTH_TOKEN_MAX_AGE is a positive integer
558+
if isinstance(config.REACTPY_AUTH_TOKEN_MAX_AGE, int) and config.REACTPY_AUTH_TOKEN_MAX_AGE < 0:
559559
errors.append(
560560
Error(
561-
"Invalid value for REACTPY_AUTH_TOKEN_TIMEOUT.",
562-
hint="REACTPY_AUTH_TOKEN_TIMEOUT should be a non-negative integer.",
561+
"Invalid value for REACTPY_AUTH_TOKEN_MAX_AGE.",
562+
hint="REACTPY_AUTH_TOKEN_MAX_AGE should be a non-negative integer.",
563563
id="reactpy_django.E029",
564564
)
565565
)

src/reactpy_django/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
"REACTPY_SESSION_MAX_AGE",
4040
259200, # Default to 3 days
4141
)
42-
REACTPY_AUTH_TOKEN_TIMEOUT: int = getattr(
42+
REACTPY_AUTH_TOKEN_MAX_AGE: int = getattr(
4343
settings,
44-
"REACTPY_AUTH_TOKEN_TIMEOUT",
44+
"REACTPY_AUTH_TOKEN_MAX_AGE",
4545
30, # Default to 30 seconds
4646
)
4747
REACTPY_CACHE: str = getattr(

src/reactpy_django/models.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ class AuthToken(models.Model):
3434

3535
@property
3636
def expired(self) -> bool:
37-
"""Check the client has exceeded the max timeout."""
38-
from reactpy_django.config import REACTPY_AUTH_TOKEN_TIMEOUT
37+
from reactpy_django.config import REACTPY_AUTH_TOKEN_MAX_AGE
3938

40-
return self.created_at < (timezone.now() - timedelta(seconds=REACTPY_AUTH_TOKEN_TIMEOUT))
39+
return self.created_at < (timezone.now() - timedelta(seconds=REACTPY_AUTH_TOKEN_MAX_AGE))
4140

4241

4342
class Config(models.Model):

src/reactpy_django/tasks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ def clean_component_sessions(verbosity: int = 1):
7272

7373

7474
def clean_auth_tokens(verbosity: int = 1):
75-
from reactpy_django.config import DJANGO_DEBUG, REACTPY_AUTH_TOKEN_TIMEOUT
75+
from reactpy_django.config import DJANGO_DEBUG, REACTPY_AUTH_TOKEN_MAX_AGE
7676
from reactpy_django.models import AuthToken
7777

7878
if verbosity >= 2:
7979
_logger.info("Cleaning ReactPy auth tokens...")
8080
start_time = timezone.now()
81-
expiration_date = timezone.now() - timedelta(seconds=REACTPY_AUTH_TOKEN_TIMEOUT)
81+
expiration_date = timezone.now() - timedelta(seconds=REACTPY_AUTH_TOKEN_MAX_AGE)
8282
synchronizer_objects = AuthToken.objects.filter(created_at__lte=expiration_date)
8383

8484
if verbosity >= 2:

0 commit comments

Comments
 (0)