File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -20,10 +20,10 @@ General Options:
20
20
in a sequence or a set to check more then one location, such as:
21
21
``('headers', 'cookies') ``. Defaults to ``['headers'] ``
22
22
``JWT_ACCESS_TOKEN_EXPIRES `` How long an access token should live before it expires. This
23
- takes a ``datetime.timedelta ``, and defaults to 15 minutes.
23
+ takes a ``datetime.timedelta `` or an `` int `` (seconds) , and defaults to 15 minutes.
24
24
Can be set to ``False `` to disable expiration.
25
25
``JWT_REFRESH_TOKEN_EXPIRES `` How long a refresh token should live before it expires. This
26
- takes a ``datetime.timedelta ``, and defaults to 30 days.
26
+ takes a ``datetime.timedelta `` or `` int `` (seconds) , and defaults to 30 days.
27
27
Can be set to ``False `` to disable expiration.
28
28
``JWT_ALGORITHM `` Which algorithm to sign the JWT with. `See here <https://pyjwt.readthedocs.io/en/latest/algorithms.html >`_
29
29
for the options. Defaults to ``'HS256' ``.
Original file line number Diff line number Diff line change @@ -186,16 +186,22 @@ def refresh_csrf_header_name(self):
186
186
@property
187
187
def access_expires (self ):
188
188
delta = current_app .config ['JWT_ACCESS_TOKEN_EXPIRES' ]
189
+ if type (delta ) is int :
190
+ delta = datetime .timedelta (seconds = delta )
189
191
if not isinstance (delta , datetime .timedelta ) and delta is not False :
190
- err = 'JWT_ACCESS_TOKEN_EXPIRES must be a datetime.timedelta or False'
192
+ err = 'JWT_ACCESS_TOKEN_EXPIRES must be a ' \
193
+ 'datetime.timedelta, int or False'
191
194
raise RuntimeError (err )
192
195
return delta
193
196
194
197
@property
195
198
def refresh_expires (self ):
196
199
delta = current_app .config ['JWT_REFRESH_TOKEN_EXPIRES' ]
200
+ if type (delta ) is int :
201
+ delta = datetime .timedelta (seconds = delta )
197
202
if not isinstance (delta , datetime .timedelta ) and delta is not False :
198
- err = 'JWT_REFRESH_TOKEN_EXPIRES must be a datetime.timedelta or False'
203
+ err = 'JWT_REFRESH_TOKEN_EXPIRES must be a ' \
204
+ 'datetime.timedelta, int or False'
199
205
raise RuntimeError (err )
200
206
return delta
201
207
Original file line number Diff line number Diff line change @@ -180,6 +180,15 @@ def test_tokens_never_expire(app):
180
180
assert config .refresh_expires is False
181
181
182
182
183
+ def test_tokens_with_int_values (app ):
184
+ app .config ['JWT_ACCESS_TOKEN_EXPIRES' ] = 300
185
+ app .config ['JWT_REFRESH_TOKEN_EXPIRES' ] = 432000
186
+
187
+ with app .test_request_context ():
188
+ assert config .access_expires == timedelta (minutes = 5 )
189
+ assert config .refresh_expires == timedelta (days = 5 )
190
+
191
+
183
192
# noinspection PyStatementEffect
184
193
def test_symmetric_secret_key (app ):
185
194
with app .test_request_context ():
You can’t perform that action at this time.
0 commit comments