def login(self, username, password):
"""Authenticate a user.
:param str username: Username of the user
:param str password: Password of the user
:raises: exceptions.AuthenticationFailed
"""
data = {
'data': {
'attributes': {
'username': username,
'password': password
},
'type': 'obtain-json-web-tokens',
}
}
response = self.post(reverse('login'), data)
if response.status_code != status.HTTP_200_OK:
raise exceptions.AuthenticationFailed()
self.credentials(
HTTP_AUTHORIZATION='{0} {1}'.format(
api_settings.JWT_AUTH_HEADER_PREFIX,
response.data['token']
)
)
评论列表
文章目录