Hello, I installed DOT and i made an application with "Authorization grant type" set as "Resource owner password-based" and "client-type" set as "Public". Using Postman i try to send a POST request to the /o/token/ url with the following:
Header
Content-Type: application/x-www-form-urlencoded
Body
client_id: "MY_CLIENT_ID"
grant_type: password
username: "MY_USERNAME"
password: "MY_PASSWORD"
and when i send the request i get this response:
{
"error": "unsupported_grant_type"
}
This was all done using django 1.10 and python 2.7. I'm not sure what exactly i'm doing wrong, can you guys help?. Thanks in advance for the reply.
client-type should be private. You should send client id and secret as basic http auth username and password.
I have the same problem using axios.js
for documentation: https://github.com/evonove/django-oauth-toolkit/issues/127
tldr
problem is that with axios requests the submitted data is not in the request's POST field, but in the body. you can change the behaviour of DOT with a setting, so that it reads the submitted data from there.
OAUTH2_PROVIDER = {
# other OAUTH2 settings
'OAUTH2_BACKEND_CLASS': 'oauth2_provider.oauth2_backends.JSONOAuthLibCore'
}
The answer from @prim-in was right and helped me. However, the explanation may be a little cryptic.
The the problem is that the django oauth toolkit expects your frontend to use this header for content-type:
"Content-Type": "application/x-www-form-urlencoded"
When you're using a JavaScript/JSON frontend, however, you're quite likely to send a Content-Type header with "application/json". If you use the "application/json" header, DOT can't read the request.POST object in the django backend. So the object is empty and your grant_type will not been seen by it.
You have to tell DOT that you are using JSON to send the data. You do this by going into your django settings.py file and adding/changing this:
OAUTH2_PROVIDER = {
# other OAUTH2 settings
'OAUTH2_BACKEND_CLASS': 'oauth2_provider.oauth2_backends.JSONOAuthLibCore'
}
It is explained quite will in the link @pirm-in prim-in provided
I get this error on the literal rest example... Not great.
I get this error on the literal rest example... Not great.
@Blanen I'm running into the same problems as you, very frustrated with the documentation. Please let us know if you figured it out.
I get this error on the literal rest example... Not great.
@Blanen I'm running into the same problems as you, very frustrated with the documentation. Please let us know if you figured it out.
were you able to figure this out, finally?!
@shellbot97 no
I get this error on the literal rest example... Not great.
@Blanen I'm running into the same problems as you, very frustrated with the documentation. Please let us know if you figured it out.
were you able to figure this out, finally?!
I figure this out!
As I can see, this problem appear 12 days ago, so I look at previous version of rest example:
And find difference
if don't write: OAUTH2_BACKEND_CLASS': 'oauth2_provider.oauth2_backends.JSONOAuthLibCore',
this rest example will work
Yes, with apologies, we merged a documentation error. See https://github.com/jazzband/django-oauth-toolkit/issues/807#issuecomment-601691819.
I don't see evidence in a quick scan of the OAuth 2.0 RFC 6749 that one is allowed to POST with a JSON body rather than form-encoded.... If you see a reference otherwise, please let me know and/or submit a PR.
I've used https://github.com/manfredsteyer/angular-oauth2-oidc and it does the POSTs using form-encoding.
Hello,
I am getting the same error, please figure out this and share it's solution.
on PostMan It's working but while i'm trying to call using frontend then I'm getting it.
error":"unsupported_grant_type"
Most helpful comment
The answer from @prim-in was right and helped me. However, the explanation may be a little cryptic.
The the problem is that the django oauth toolkit expects your frontend to use this header for content-type:
"Content-Type": "application/x-www-form-urlencoded"When you're using a JavaScript/JSON frontend, however, you're quite likely to send a Content-Type header with "application/json". If you use the "application/json" header, DOT can't read the request.POST object in the django backend. So the object is empty and your grant_type will not been seen by it.
You have to tell DOT that you are using JSON to send the data. You do this by going into your django settings.py file and adding/changing this:
It is explained quite will in the link @pirm-in prim-in provided