Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit a7a09b5

Browse files
committed
[refresh-token] renamed JWT_TOKEN_REFRESH_LIMIT -> JWT_REFRESH_EXPIRATION_DELTA
1 parent e4a3c66 commit a7a09b5

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ Pass in an existing token to the refresh endpoint as follows: `{"token": EXISTIN
7373
$ curl -X POST -H "Content-Type: application/json" -d '{"token":"<EXISTING_TOKEN>}' http://localhost:8000/api-token-refresh/
7474
```
7575

76-
Refresh with tokens can be repeated (token1 -> token2 -> token3), but this chain of token stores the time that the original token (obtained with username/password credentials), as `orig_iat`. You can only keep refreshing tokens up to `JWT_TOKEN_REFRESH_LIMIT`.
76+
Refresh with tokens can be repeated (token1 -> token2 -> token3), but this chain of token stores the time that the original token (obtained with username/password credentials), as `orig_iat`. You can only keep refreshing tokens up to `JWT_REFRESH_EXPIRATION_DELTA`.
7777

78-
A typical use case might be a web app where you'd like to keep the user "logged in" the site without having to re-enter their password, or get kicked out by surprise before their token expired. Imagine they had a 1-hour token and are just at the last minute while they're still doing something. With mobile you could perhaps store the username/password to get a new token, but this is not a great idea in a browser. Each time the user loads the page, you can check if there is an existing non-expired token and if it's close to being expired, refresh it to extend their session. In other words, if a user is actively using your site, they can keep their "session" alive.
78+
A typical use case might be a web app where you'd like to keep the user "logged in" the site without having to re-enter their password, or get kicked out by surprise before their token expired. Imagine they had a 1-hour token and are just at the last minute while they're still doing something. With mobile you could perhaps store the username/password to get a new token, but this is not a great idea in a browser. Each time the user loads the page, you can check if there is an existing non-expired token and if it's close to being expired, refresh it to extend their session. In other words, if a user is actively using your site, they can keep their "session" alive.
7979

8080
## Additional Settings
8181
There are some additional settings that you can override similar to how you'd do it with Django REST framework itself. Here are all the available defaults.
@@ -90,7 +90,7 @@ JWT_AUTH = {
9090

9191
'JWT_PAYLOAD_HANDLER':
9292
'rest_framework_jwt.utils.jwt_payload_handler',
93-
93+
9494
'JWT_PAYLOAD_GET_USER_ID_HANDLER':
9595
'rest_framework_jwt.utils.jwt_get_user_id_from_payload_handler',
9696

@@ -100,9 +100,9 @@ JWT_AUTH = {
100100
'JWT_VERIFY_EXPIRATION': True,
101101
'JWT_LEEWAY': 0,
102102
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
103-
103+
104104
'JWT_ALLOW_TOKEN_REFRESH': False,
105-
'JWT_TOKEN_REFRESH_LIMIT': datetime.timedelta(days=7),
105+
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
106106
}
107107
```
108108
This packages uses the JSON Web Token Python implementation, [PyJWT](https://github.com/progrium/pyjwt) and allows to modify some of it's available options.
@@ -156,16 +156,13 @@ Default is `datetime.timedelta(seconds=300)`(5 minutes).
156156
### JWT_ALLOW_TOKEN_REFRESH
157157
Enable token refresh functionality. Token issued from `rest_framework_jwt.views.obtain_jwt_token` will have an `orig_iat` field. Default is `False`
158158

159-
### JWT_TOKEN_REFRESH_LIMIT
159+
### JWT_REFRESH_EXPIRATION_DELTA
160160
Limit on token refresh, is a `datetime.timedelta` instance. This is how much time after the original token that future tokens can be refreshed from.
161161

162162
Default is `datetime.timedelta(days=7)` (7 days).
163163

164164
### JWT_PAYLOAD_HANDLER
165165
Specify a custom function to generate the token payload
166-
166+
167167
### JWT_PAYLOAD_GET_USER_ID_HANDLER
168168
If you store `user_id` differently than the default payload handler does, implement this function to fetch `user_id` from the payload.
169-
170-
171-

rest_framework_jwt/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def validate(self, attrs):
101101
orig_iat = payload.get('orig_iat')
102102
if orig_iat:
103103
# Verify expiration
104-
refresh_limit = api_settings.JWT_TOKEN_REFRESH_LIMIT
104+
refresh_limit = api_settings.JWT_REFRESH_EXPIRATION_DELTA
105105
if isinstance(refresh_limit, timedelta):
106106
refresh_limit = (refresh_limit.days * 24 * 3600 +
107107
refresh_limit.seconds)

rest_framework_jwt/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
2828

2929
'JWT_ALLOW_TOKEN_REFRESH': False,
30-
'JWT_TOKEN_REFRESH_LIMIT': datetime.timedelta(days=7),
30+
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
3131
}
3232

3333
# List of settings that may be in string import notation.

rest_framework_jwt/tests/test_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def test_refresh_jwt_after_refresh_expiration(self):
237237
"""
238238
client = APIClient(enforce_csrf_checks=True)
239239

240-
orig_iat = (datetime.utcnow() - api_settings.JWT_TOKEN_REFRESH_LIMIT -
240+
orig_iat = (datetime.utcnow() - api_settings.JWT_REFRESH_EXPIRATION_DELTA -
241241
timedelta(seconds=5))
242242
token = self.create_token(
243243
self.user,

0 commit comments

Comments
 (0)