Neo
Neo

Reputation: 5228

Django OAuth Toolkit setup issue

I am following https://django-oauth-toolkit.readthedocs.org/en/0.7.0/rest-framework/getting_started.html for setting up Django OAuth Toolkit with rest framework.

As on step 4: https://django-oauth-toolkit.readthedocs.org/en/0.7.0/rest-framework/getting_started.html#step-4-get-your-token-and-use-your-api

It says to get token, we need to do a curl like:

curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" http://<client_id>:<client_secret>@localhost:8000/o/token/

My Actual curl request for this process looks something like this(for already generated client_id and client_secret)

curl -X POST -d "grant_type=password&username=test&password=test" http://mbqvonqO7sI1lrh87uDd.C1U..NbKTb@0=eCM8Fl::2O=!0ZjE5UCha0UW?Oie-XCVUn;[email protected]!KLoDqVz7L-3.FfjP9v6yYyu2ghxObnIdIWppu=J@RPxPOfU@Q7KPt7da.?Bg0o5kCt5tY:[email protected]:8000/o/token/

which didn't return any response and gives an error "bash: !0: event not found"

Any wrong in call made?

Upvotes: 3

Views: 1283

Answers (3)

j3py
j3py

Reputation: 1267

I had the same problem as the OP and this was the only solution that worked for me:

curl -X POST -d 'grant_type=password&username=<username>&password=<password>' --user '<client_id>:<client_secret>' 'http://localhost:8000/o/token/'

I found this solution at Django OAuth Toolkit's Github issue #167. There is a great explanation there.

Upvotes: 0

Neo
Neo

Reputation: 5228

Issue is with the "client id" and "client secret" generated during register application(http://django-oauth-toolkit.readthedocs.org/en/0.7.0/rest-framework/getting_started.html#step-3-register-an-application)

"client id" and "client secret" contains special characters which can't be used with curl request in the mentioned way in documentation.

We can use it with the way suggested by Almalki as:

curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD" http://localhost:8000/o/token/

Upvotes: 2

almalki
almalki

Reputation: 4785

You can set client_id and client_secret as POST parameters:

curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD" http://localhost:8000/o/token/

Upvotes: 1

Related Questions