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

Commit 90303f0

Browse files
committed
[refresh-token] make wording consistent, replace RENEW with REFRESH
1 parent 4c3cdce commit 90303f0

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ $ curl -H "Authorization: JWT <your_token>" http://localhost:8000/protected-url/
6262
```
6363

6464
## Refresh Token
65-
If `JWT_ALLOW_TOKEN_RENEWAL` is True, issued tokens can be "refreshed" to obtain a new brand token with renewed expiration time. Add a URL pattern like this:
65+
If `JWT_ALLOW_TOKEN_REFRESH` is True, issued tokens can be "refreshed" to obtain a new brand token with renewed expiration time. Add a URL pattern like this:
6666
```python
6767
url(r'^api-token-refresh/', 'rest_framework_jwt.views.refresh_jwt_token'),
6868
```
@@ -73,7 +73,7 @@ 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_RENEWAL_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_TOKEN_REFRESH_LIMIT`.
7777

7878

7979
## Additional Settings
@@ -100,8 +100,8 @@ JWT_AUTH = {
100100
'JWT_LEEWAY': 0,
101101
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
102102

103-
'JWT_ALLOW_TOKEN_RENEWAL': False,
104-
'JWT_TOKEN_RENEWAL_LIMIT': datetime.timedelta(days=7),
103+
'JWT_ALLOW_TOKEN_REFRESH': False,
104+
'JWT_TOKEN_REFRESH_LIMIT': datetime.timedelta(days=7),
105105
}
106106
```
107107
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.
@@ -152,11 +152,11 @@ This is an instance of Python's `datetime.timedelta`. This will be added to `dat
152152

153153
Default is `datetime.timedelta(seconds=300)`(5 minutes).
154154

155-
### JWT_ALLOW_TOKEN_RENEWAL
156-
Enable token renewal functionality. Token issued from `rest_framework_jwt.views.obtain_jwt_token` will have an `orig_iat` field. Default is `False`
155+
### JWT_ALLOW_TOKEN_REFRESH
156+
Enable token refresh functionality. Token issued from `rest_framework_jwt.views.obtain_jwt_token` will have an `orig_iat` field. Default is `False`
157157

158-
### JWT_TOKEN_RENEWAL_LIMIT
159-
Limit on token renewal, is a `datetime.timedelta` instance. This is how much time after the original token that future tokens can be refreshed from.
158+
### JWT_TOKEN_REFRESH_LIMIT
159+
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.
160160

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

rest_framework_jwt/serializers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def validate(self, attrs):
4949

5050
# Include original issued at time for a brand new token,
5151
# to allow token refresh
52-
if api_settings.JWT_ALLOW_TOKEN_RENEWAL:
52+
if api_settings.JWT_ALLOW_TOKEN_REFRESH:
5353
payload['orig_iat'] = timegm(
5454
datetime.utcnow().utctimetuple()
5555
)
@@ -101,13 +101,13 @@ def validate(self, attrs):
101101
orig_iat = payload.get('orig_iat')
102102
if orig_iat:
103103
# Verify expiration
104-
renewal_limit = api_settings.JWT_TOKEN_RENEWAL_LIMIT
105-
if isinstance(renewal_limit, timedelta):
106-
renewal_limit = (renewal_limit.days * 24 * 3600 +
107-
renewal_limit.seconds)
104+
refresh_limit = api_settings.JWT_TOKEN_REFRESH_LIMIT
105+
if isinstance(refresh_limit, timedelta):
106+
refresh_limit = (refresh_limit.days * 24 * 3600 +
107+
refresh_limit.seconds)
108108
expiration_timestamp = (
109109
orig_iat +
110-
int(renewal_limit)
110+
int(refresh_limit)
111111
)
112112
now_timestamp = timegm(datetime.utcnow().utctimetuple())
113113
if now_timestamp > expiration_timestamp:

rest_framework_jwt/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
'JWT_LEEWAY': 0,
2727
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
2828

29-
'JWT_ALLOW_TOKEN_RENEWAL': False,
30-
'JWT_TOKEN_RENEWAL_LIMIT': datetime.timedelta(days=7),
29+
'JWT_ALLOW_TOKEN_REFRESH': False,
30+
'JWT_TOKEN_REFRESH_LIMIT': 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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class RefreshJSONWebTokenTests(BaseTestCase):
164164

165165
def setUp(self):
166166
super(RefreshJSONWebTokenTests, self).setUp()
167-
api_settings.JWT_ALLOW_TOKEN_RENEWAL = True
167+
api_settings.JWT_ALLOW_TOKEN_REFRESH = True
168168

169169
def get_token(self):
170170
client = APIClient(enforce_csrf_checks=True)
@@ -231,13 +231,13 @@ def test_refresh_jwt_fails_with_expired_token(self):
231231
self.assertRegexpMatches(response.data['non_field_errors'][0],
232232
'Signature has expired')
233233

234-
def test_refresh_jwt_after_renewal_expiration(self):
234+
def test_refresh_jwt_after_refresh_expiration(self):
235235
"""
236-
Test that token can't be refreshed after token renewal limit
236+
Test that token can't be refreshed after token refresh limit
237237
"""
238238
client = APIClient(enforce_csrf_checks=True)
239239

240-
orig_iat = (datetime.utcnow() - api_settings.JWT_TOKEN_RENEWAL_LIMIT -
240+
orig_iat = (datetime.utcnow() - api_settings.JWT_TOKEN_REFRESH_LIMIT -
241241
timedelta(seconds=5))
242242
token = self.create_token(
243243
self.user,
@@ -253,5 +253,5 @@ def test_refresh_jwt_after_renewal_expiration(self):
253253

254254
def tearDown(self):
255255
# Restore original settings
256-
api_settings.JWT_ALLOW_TOKEN_RENEWAL = \
257-
DEFAULTS['JWT_ALLOW_TOKEN_RENEWAL']
256+
api_settings.JWT_ALLOW_TOKEN_REFRESH = \
257+
DEFAULTS['JWT_ALLOW_TOKEN_REFRESH']

0 commit comments

Comments
 (0)