Discussion:
Django Oauth Toolkit: POST to Token Generation Service Fails but Curl Succeeds
Foobar
2018-11-13 19:43:25 UTC
Permalink
Using Django OAuth Toolkit, I have authorization_grant_type set to password
and skip_authorization set to true. I am able to generate tokens and
refresh tokens using curl without an issue using the following command:

curl -X POST -d
"grant_type=password&username=username&password=password"
http://p6ge67ihXcwECuy7Z7iomyv16VlEk4uX6B886UWl:***@localhost:8000/o/token/

But when I try substituting this command with a POST and invoke that POST
from a Django view, I get the following:

<Response [401]>
Unauthorized: /o/token/

Any clue why this happening? My POST code is as follows:

data = {
'grant_type': 'password',
'username': 'username',
'password': 'password'
}

response =
requests.post('http://p6ge67ihXcwECuy7Z7iomyv16VlEk4uX6B886UWl:***@localhost:8000/o/token/',
data=data)

What am I missing? Any help would be greatly appreciated. Thanks.
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...