This is a small app for an example of how to configure together Django, Django REST Framework and Django Oauth Toolkit.
- Python 3.6.3
- Clone project.
git clone git@github.com:ryanrodemoyer/DjangoOauthExample.git
- Switch directory
cd DjangoOauthExample
- Install requirements.
pip install -r requirements.txt
- Migrate database.
python manage.py migrate
- Create user.
python manage.py createsuperuser
- Run!
python manage.py runserver
- Admin Login @ http://localhost:8000/admin.
- Register/View applications @ http://localhost:8000/o/applications.
- Token endpoint @ http://localhost:8000/o/token
- Register new application.
- Name: <your choice>.
- Client type: confidential.
- Authorization grant type: Authorization code.
- Redirect urls: http://django-oauth-toolkit.herokuapp.com/consumer/exchange/
- Follow the steps @ http://django-oauth-toolkit.herokuapp.com/consumer/ to get a token.
- Verify /api/users/ route is protected.
curl http://localhost:8000/api/users/
. - Request /api/users/ to see data.
curl -H "Authorization: Bearer <your_access_token>" http://localhost:8000/api/users/
- Register new application
- Name: <your choice>.
- Client type: confidential.
- Authorization grant type: Resource owner password-based.
- Redirect urls: <blank>
- Verify /api/users/ route is protected.
curl http://localhost:8000/api/users/
- Get a token. Use the super user credentials from above in Install or create a new user via Django Admin and use those credentials.
curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" -u "<client_id>:<client_secret>" http://localhost:8000/o/token/
- Request /api/users/ to see data.
curl -H "Authorization: Bearer <your_access_token>" http://localhost:8000/api/users/
Based mostly on the documentation at https://django-oauth-toolkit.readthedocs.io.