Skip to content

tyaga001/django-authorization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Django-Authorization

How to Implement Authorization in Django

Hospital System

License

Description

A Django project for managing a hospital system using Permit.io for authorization. The project includes a RESTful API for managing patients, doctors, and appointments. The API is secured using ABAC (Attribute-Based Access Control) and RBAC (Role-Based Access Control) policies. The project also includes a PDP (Policy Decision Point) microservice for evaluating access control policies.

Features

  • ABAC (Attribute-Based Access Control)
  • CRUD operations
  • RESTful API
  • User authentication
  • Role-based access control
  • ReBAC (Relationship-Based Access Control)

Installation

  1. Clone the repository: https://github.com/tyaga001/django-authorization.git

  2. Cd into the project directory:

    cd hsystem
  3. Create a virtual environment:

    python3 -m venv venv
  4. Activate virtualenv:

    For general use:

    source venv/bin/activate

    For zsh users:

    source venv/bin/activate.zsh

    For bash users:

    source venv/bin/activate.bash

    For fish users:

    source venv/bin/activate.fish
  5. Install the dependencies:

    pip install -r requirements.txt
  6. Apply database migrations:

    python manage.py migrate

    Or

    python manage.py migrate --run-syncdb

    Or

    python manage.py makemigrations hsystem
    python manage.py migrate
  7. Start the development server:

    python manage.py runserver 5000

Run your local PDP Microservice container

If you do not have Docker installed as of yet, click here to install Docker.

Pull the container

Run the following command to pull the PDP Microservice container:

docker pull permitio/pdp-v2:latest

Run the container

Remember to replace <YOUR_API_KEY> with the Secret Key you obtained from your dashboard.

docker run -it -p 7766:7000 --env PDP_DEBUG=True --env PDP_API_KEY=<YOUR_API_KEY> permitio/pdp-v2:latest

Usage

  1. Create a superuser: python manage.py createsuperuser
  2. Access the admin panel: http://localhost:5000/admin/
  3. Access the API: http://localhost:5000/api/
  4. Access the documentation: http://localhost:5000/docs/

Test the App

Run the following command in a separate terminal to test whether the app is working as expected:

curl -X GET http://localhost:5000/patients/1/

License

This project is licensed under the MIT License.

Blog

How to Implement Authorization with Django

Additional Resources

Thank you for reading, and happy coding.