Skip to content

Adding REFRESH_TOKEN_EXPIRE_SECONDS#3226

Merged
annagav merged 2 commits intomainfrom
ag/clear_tokens_expire
Jan 16, 2026
Merged

Adding REFRESH_TOKEN_EXPIRE_SECONDS#3226
annagav merged 2 commits intomainfrom
ag/clear_tokens_expire

Conversation

@annagav
Copy link
Contributor

@annagav annagav commented Jan 16, 2026

What are the relevant tickets?

Related to #3142

Description (What does it do?)

Adds REFRESH_TOKEN_EXPIRE_SECONDS so that the cleartokens management command when run removes those refresh tokens whose lifetime is greater than the amount specified by REFRESH_TOKEN_EXPIRE_SECONDS settings.

How can this be tested?

Make sure you have tokens that are older than 1 month.

Run python manage.py cleartokens

Check that old tokens got removed.

@github-actions
Copy link

OpenAPI Changes

Show/hide ## Changes for v0.yaml:
## Changes for v0.yaml:


## Changes for v1.yaml:


## Changes for v2.yaml:


Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

main/settings.py Outdated
Comment on lines 1564 to 1568
REFRESH_TOKEN_EXPIRE_SECONDS = get_int(
name="REFRESH_TOKEN_EXPIRE_SECONDS",
default=60 * 60 * 24 * 30, # 30 days
description="Number of seconds until a refresh token expires",
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be nested under a namespaced dictionary object for it to take effect https://django-oauth-toolkit.readthedocs.io/en/latest/settings.html#settings

Copy link
Contributor

@cp-at-mit cp-at-mit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how many of these expired tokens we regularly accumulate between running this command, but if it's a lot should we consider adding the following:
To prevent the CPU and RAM high peaks during deletion process use CLEAR_EXPIRED_TOKENS_BATCH_SIZE and CLEAR_EXPIRED_TOKENS_BATCH_INTERVAL settings to adjust the process speed.

@annagav annagav force-pushed the ag/clear_tokens_expire branch from a260ef1 to 9079f76 Compare January 16, 2026 16:57
@annagav annagav force-pushed the ag/clear_tokens_expire branch from b2d0e3b to 650dd44 Compare January 16, 2026 17:00
@annagav annagav requested a review from blarghmatey January 16, 2026 17:36
@annagav annagav merged commit c3e979a into main Jan 16, 2026
9 checks passed
@odlbot odlbot mentioned this pull request Jan 21, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants