New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting { "error": "unsupported_grant_type" } #127

affo opened this Issue Jun 11, 2014 · 5 comments


None yet
5 participants

affo commented Jun 11, 2014

I am writing an AngularJS application that consumes mi REST Framework APIs.
I am using DOT as oAuth2 provider.
The problem is that the same request sent with cURL is successful, once it is sent with an XHR request I get:

{ "error": "unsupported_grant_type" }

I suspected an encoding problem, so I tried to change headers putting:

'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'

But it doesn't work...
For precision's sake, XHR requests are sent with Restangular.

Thank you in advance


This comment has been minimized.

affo commented Jun 11, 2014

had to use:

 var data = {
        foo: "foo",
        bar: "bar",

 data = $.param(data); //jquery perfectly encondes data

 Restangular.all('oauth/token').post(data, undefined, {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',

Isn't it possible to make DOT accept application/json as input?


This comment has been minimized.

zhenghongzhi commented Dec 10, 2014

I have walk through the source code and it is not possible to accept application/json as input :(


This comment has been minimized.


palazzem commented Apr 20, 2015

Hi (and sorry for taking so long for an answer),
the default behavior is to enforce the use of application/x-www-form-urlencoded Content-Type.
The OAuthLibCore implementation extracts the request body using request.POST dictionary, which is empty for a request that uses application/json Content-Type.

Anyhow, from your settings, you can set the JSONOAuthLibCore class that supports application/json. The following example shows how to use the new backend class:

    # other OAUTH2 settings
    'OAUTH2_BACKEND_CLASS': 'oauth2_provider.oauth2_backends.JSONOAuthLibCore'

This feature will be released in the milestone 0.9.0 and is already merged in master.

@palazzem palazzem closed this Apr 20, 2015


This comment has been minimized.

sacgup commented Sep 22, 2015

Hi, Isn't it possible that OAUTH2_BACKEND_CLASS is used based on the content type of the request.
I actually want to support 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' as well as 'application/json'. Is there any way i can do it ?


This comment has been minimized.

theromis commented Jan 21, 2016

+1 I want conditional content type selector as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment