Django OAuth toolkit testing result unsupported_grant_type

117 views
Skip to first unread message

Osman Makhtoomnejad

unread,
Mar 11, 2024, 2:36:34 AMMar 11
to Django REST framework
Hi everyone
I want to call the Django OAuth toolkit's default /auth/token API and get a new token for the user.
When I call that API by Postman it is OK and the responses are correct but when I call it with the same information by the DRF APITestCase client it says: "unsupported_grant_type"

Thanks for your help

My code is below:


def setUp(self):
self.client = APIClient()
self.client_id = '<ID>'
self.client_secret = '<KEY>'
self.grant_type = 'client_credentials'
self.auth_data = urlencode(
{'client_id': self.client_id, 'client_secret': self.client_secret, 'grant_type': self.grant_type}
)

def _get_token(self):
response = self.client.post(
path='/auth/token/',
data=self.auth_data,
content_type='application/x-www-form-urlencoded',
)
token_data = json.loads(response.content)
print(token_data)
return token_data
Reply all
Reply to author
Forward
0 new messages