mirror of
https://github.com/wassname/flask-security.git
synced 2026-06-27 16:10:11 +08:00
Add configuration for token expiration
This commit is contained in:
@@ -36,3 +36,4 @@ Rotem Yaari
|
|||||||
Srijan Choudhary
|
Srijan Choudhary
|
||||||
Tristan Escalada
|
Tristan Escalada
|
||||||
Vadim Kotov
|
Vadim Kotov
|
||||||
|
Walt Askew
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ Core
|
|||||||
``SECURITY_TOKEN_AUTHENTICATION_HEADER`` Specifies the HTTP header to read when
|
``SECURITY_TOKEN_AUTHENTICATION_HEADER`` Specifies the HTTP header to read when
|
||||||
using token authentication. Defaults to
|
using token authentication. Defaults to
|
||||||
``Authentication-Token``.
|
``Authentication-Token``.
|
||||||
|
``SECURITY_TOKEN_MAX_AGE`` Specifies the number of seconds before
|
||||||
|
an authentication token expires.
|
||||||
|
Defaults to None, meaning the token
|
||||||
|
never expires.
|
||||||
``SECURITY_DEFAULT_HTTP_AUTH_REALM`` Specifies the default authentication
|
``SECURITY_DEFAULT_HTTP_AUTH_REALM`` Specifies the default authentication
|
||||||
realm when using basic HTTP auth.
|
realm when using basic HTTP auth.
|
||||||
Defaults to ``Login Required``
|
Defaults to ``Login Required``
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ _default_config = {
|
|||||||
'EMAIL_SENDER': 'no-reply@localhost',
|
'EMAIL_SENDER': 'no-reply@localhost',
|
||||||
'TOKEN_AUTHENTICATION_KEY': 'auth_token',
|
'TOKEN_AUTHENTICATION_KEY': 'auth_token',
|
||||||
'TOKEN_AUTHENTICATION_HEADER': 'Authentication-Token',
|
'TOKEN_AUTHENTICATION_HEADER': 'Authentication-Token',
|
||||||
|
'TOKEN_MAX_AGE': None,
|
||||||
'CONFIRM_SALT': 'confirm-salt',
|
'CONFIRM_SALT': 'confirm-salt',
|
||||||
'RESET_SALT': 'reset-salt',
|
'RESET_SALT': 'reset-salt',
|
||||||
'LOGIN_SALT': 'login-salt',
|
'LOGIN_SALT': 'login-salt',
|
||||||
@@ -192,7 +193,7 @@ def _user_loader(user_id):
|
|||||||
|
|
||||||
def _token_loader(token):
|
def _token_loader(token):
|
||||||
try:
|
try:
|
||||||
data = _security.remember_token_serializer.loads(token)
|
data = _security.remember_token_serializer.loads(token, max_age=_security.token_max_age)
|
||||||
user = _security.datastore.find_user(id=data[0])
|
user = _security.datastore.find_user(id=data[0])
|
||||||
if user and safe_str_cmp(md5(user.password), data[1]):
|
if user and safe_str_cmp(md5(user.password), data[1]):
|
||||||
return user
|
return user
|
||||||
|
|||||||
Reference in New Issue
Block a user