Django – OAuth Test Sample

An OAuth sample code base on Django.

Django Commands

  • pip3 install django djangorestframework django-oauth-toolkit
  • django-admin startproject oauth_test
  • cd oauth_test
  • python3 manage.py startapp test_app
  • python3 manage.py makemigrations
  • python3 manage.py migrate
  • python3 manage.py createsuperuser
  • python3 manage.py runserver
  • We can test by using Postman application.

Setup OAuth in project’s admin management site

  • Default site url: http://127.0.0.1:8000/admin
  • Attention! The Client secret need save copy on create step! After creating, the Client secret field only shows the hashed client secret not original. (We need use the original client secret for auth)

Project Structure

Project Structure

.\oauth_test\settings.py

.\oauth_test\urls.py

.\test_app\apps.py

.\test_app\models.py

.\test_app\serializers.py

.\test_app\views.py

.\test_app\urls.py

Postman Test for get auth – Post

Use the original Client secret.

Postman Test for use auth – Get

留言

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.