Following the django rest getting started tutorial until the part where is asks to get the access token through curl. With three different registered applications, many users and groups (with all permissions), I was still getting a {"error": "unauthorized_client"} as response.
I've traced the code using pycharm's debug environment and I noticed that the authorization error happened at oauth2_validators.py#L247.
Take a look at this screen-shot:

The value of request.client.authorization_grant_type is u'authorization-code', which IS NOT in the dictionary GRANT_TYPE_MAPPING (in contrast with u'authorization_code', which IS in the ditionary). Is there any chance that some kind of name-conversion has been forgotten? Or maybe the values in the application creation form are incorrect.
Hi @lucasdavid
I think you're getting the unathorized_error because you 're not authenticating the access token request using your client_id and client_secret.
Can you post the curl command you're using to get access token?
Oh man. My sincere apologies! It wasn't working because I'd selected authorization-code in the /o/applications/register (as pointed by the tutorial part 1) instead of Resource owner password-based. I've updated it and now it works perfectly.
Here is the curl:
curl -X POST -d "grant_type=password&username=ldavid&password=root" -u'BL4tt9x9bAeTEhksHSDOM8Nan2zKvJRg7d5gINCq:vBowBIbUSHlN7cKFxBScRSZCB6KkvqQ8PMXnfi5tU34alQbBLuJr05thoTwjJ6Z0tRWcB9murmNHsKQHuviwXhV57m6Cv1oAfZS9qRhq6t4NR7pOmvMhlHDJqsARLUGR' http://127.0.0.1:8000/o/token/
Anyways, should it really be assigning the value authentication-code instead of authentication_code to request.client.authorization_grant_type? That seems like a bug, considering GRANT_TYPE_MAPPING does not have a key named authentication-code.
Oh, wait. I've just understood the logic here. There is no bug.
Most helpful comment
Oh man. My sincere apologies! It wasn't working because I'd selected
authorization-codein the/o/applications/register(as pointed by the tutorial part 1) instead ofResource owner password-based. I've updated it and now it works perfectly.Here is the curl:
Anyways, should it really be assigning the value
authentication-codeinstead ofauthentication_codetorequest.client.authorization_grant_type? That seems like a bug, consideringGRANT_TYPE_MAPPINGdoes not have a key namedauthentication-code.