Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Stop 500's on a non-JSON /auth request #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions flask_jwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ def _default_request_handler():


def _default_auth_request_handler():
data = request.get_json()
username = data.get(current_app.config.get('JWT_AUTH_USERNAME_KEY'), None)
password = data.get(current_app.config.get('JWT_AUTH_PASSWORD_KEY'), None)
criterion = [username, password, len(data) == 2]
data = request.get_json() or {}
username = data.get(current_app.config.get('JWT_AUTH_USERNAME_KEY'))
password = data.get(current_app.config.get('JWT_AUTH_PASSWORD_KEY'))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second parameter to get() is already None - it can be safely omitted.

criteria = [username, password, len(data) == 2]

if not all(criterion):
if not all(criteria):
raise JWTError('Bad Request', 'Invalid credentials')

identity = _jwt.authentication_callback(username, password)
Expand Down