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

Commit a62b8f6

Browse files
authored
APIJWTClient login with any credential format
We're using emails as usernames in our project, but the `APIJWTClient.login` method assumes usernames are used. Another option would be to use `get_username_field` [1](https://github.com/GetBlimp/django-rest-framework-jwt/blob/00f76e44da4a2b62075696cce1f583dd735ff197/rest_framework_jwt/compat.py#L22), but I think this is the better solution. It matches what `django.test.client.Client` does [2](https://github.com/django/django/blob/9baf692a58de78dba13aa582098781675367c329/django/test/client.py#L613).
1 parent 82f671b commit a62b8f6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

rest_framework_jwt/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55

66
class APIJWTClient(APIClient):
7-
def login(self, username, password):
7+
def login(self, **credentials):
88
"""
99
Returns True if login is possible; False if the provided credentials
1010
are incorrect, or the user is inactive.
1111
"""
12-
response = self.post('/api-token-auth/', {"username": username, "password": password},
13-
format='json')
12+
13+
response = self.post('/api-token-auth/', credentials, format='json')
1414
if response.status_code == status.HTTP_200_OK:
1515
self.credentials(
1616
HTTP_AUTHORIZATION="{0} {1}".format(api_settings.JWT_AUTH_HEADER_PREFIX, response.data['token']))

0 commit comments

Comments
 (0)