Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flask_jwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _default_jwt_payload_handler(identity):
iat = datetime.utcnow()
exp = iat + current_app.config.get('JWT_EXPIRATION_DELTA')
nbf = iat + current_app.config.get('JWT_NOT_BEFORE_DELTA')
identity = getattr(identity, 'id') or identity['id']
identity = getattr(identity, 'id', None) or identity['id']
return {'exp': exp, 'iat': iat, 'nbf': nbf, 'identity': identity}


Expand Down
13 changes: 13 additions & 0 deletions tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,16 @@ def custom_auth_request_handler():
with app.test_client() as c:
resp, jdata = post_json(c, '/auth', {})
assert jdata == {'hello': 'world'}


def test_authentication_handler_with_dictionary_result(client, jwt, user):
@jwt.authentication_handler
def authenticate(username, password):
if username == user.username and password == user.password:
return dict(id=user.id, username=user.username, password=user.password)
return None

resp, jdata = post_json(
client, '/auth', {'username': user.username, 'password': user.password})
assert resp.status_code == 200
assert 'access_token' in jdata
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ deps =
-r{toxinidir}/requirements-dev.txt

commands =
py.test --clearcache {posargs} ./tests
py.test --cache-clear {posargs} ./tests