Skip to content

Template project using Django/DRF/OAuth on the backend and Angular 5 on the frontend.

License

Notifications You must be signed in to change notification settings

ryanrodemoyer/DjangoRestOauthAngularTemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FOR NOW THIS DOCUMENTATION IS INCORRECT

Django Oauth Example

About

This is a small app for an example of how to configure together Django, Django REST Framework and Django Oauth Toolkit.

Requirements

  • Python 3.6.3

Install

  1. Clone project.
    git clone git@github.com:ryanrodemoyer/DjangoOauthExample.git
  2. Switch directory
    cd DjangoOauthExample
  3. Install requirements.
    pip install -r requirements.txt
  4. Migrate database.
    python manage.py migrate
  5. Create user.
    python manage.py createsuperuser
  6. Run!
    python manage.py runserver

Usage

Views

  1. Admin Login @ http://localhost:8000/admin.
  2. Register/View applications @ http://localhost:8000/o/applications.
  3. Token endpoint @ http://localhost:8000/o/token

Getting A Token

Authorization Code

  1. Register new application.
  2. Follow the steps @ http://django-oauth-toolkit.herokuapp.com/consumer/ to get a token.
  3. Verify /api/users/ route is protected.
    curl http://localhost:8000/api/users/.
  4. Request /api/users/ to see data.
    curl -H "Authorization: Bearer <your_access_token>" http://localhost:8000/api/users/

Resource Owner Password

  1. Register new application
    • Name: <your choice>.
    • Client type: confidential.
    • Authorization grant type: Resource owner password-based.
    • Redirect urls: <blank>
  2. Verify /api/users/ route is protected.
    curl http://localhost:8000/api/users/
  3. 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/
  4. Request /api/users/ to see data.
    curl -H "Authorization: Bearer <your_access_token>" http://localhost:8000/api/users/

Credits

Based mostly on the documentation at https://django-oauth-toolkit.readthedocs.io.

Projects

About

Template project using Django/DRF/OAuth on the backend and Angular 5 on the frontend.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published