Django-oauth-toolkit: Can't request access token with curl

Created on 31 Mar 2015  路  3Comments  路  Source: jazzband/django-oauth-toolkit

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:
screenshot from 2015-03-31 16 17 59

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.

Most helpful comment

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lokilak picture lokilak  路  4Comments

michaeltcoelho picture michaeltcoelho  路  6Comments

clintonb picture clintonb  路  6Comments

EmilTemirov picture EmilTemirov  路  5Comments

IvanAnishchuk picture IvanAnishchuk  路  6Comments