https://github.com/tyaga001/django-authorization
How to Implement Authorization in Django
https://github.com/tyaga001/django-authorization
authorization blog django python
Last synced: about 1 month ago
JSON representation
How to Implement Authorization in Django
- Host: GitHub
- URL: https://github.com/tyaga001/django-authorization
- Owner: tyaga001
- License: mit
- Created: 2024-05-22T13:38:27.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-01T18:50:41.000Z (almost 2 years ago)
- Last Synced: 2025-03-22T06:43:48.295Z (over 1 year ago)
- Topics: authorization, blog, django, python
- Language: Python
- Homepage: https://www.permit.io/blog/fine-grained-authorization-with-django
- Size: 1.98 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Django-Authorization
How to Implement Authorization in Django
# Hospital System
[](https://opensource.org/licenses/MIT)
## Description
A Django project for managing a hospital system using [Permit.io](https://app.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:**
```sh
cd hsystem
```
3. **Create a virtual environment:**
```sh
python3 -m venv venv
```
4. **Activate virtualenv:**
For general use:
```sh
source venv/bin/activate
```
For zsh users:
```sh
source venv/bin/activate.zsh
```
For bash users:
```sh
source venv/bin/activate.bash
```
For fish users:
```sh
source venv/bin/activate.fish
```
5. **Install the dependencies:**
```sh
pip install -r requirements.txt
```
6. **Apply database migrations:**
```sh
python manage.py migrate
```
Or
```sh
python manage.py migrate --run-syncdb
```
Or
```sh
python manage.py makemigrations hsystem
python manage.py migrate
```
7. **Start the development server:**
```sh
python manage.py runserver 5000
```
## Run your local PDP Microservice container
If you do not have Docker installed as of yet, click [here](https://docs.docker.com/get-docker/) to install Docker.
### Pull the container
Run the following command to pull the PDP Microservice container:
```bash
docker pull permitio/pdp-v2:latest
```
### Run the container
Remember to replace with the Secret Key you obtained from your dashboard.
```bash
docker run -it -p 7766:7000 --env PDP_DEBUG=True --env PDP_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:
```bash
curl -X GET http://localhost:5000/patients/1/
```
## License
This project is licensed under the [MIT License](LICENSE).
## Blog
[How to Implement Authorization with Django](https://www.permit.io/blog/fine-grained-authorization-with-django)
## Additional Resources
- Follow my articles on [freeCodeCamp](https://www.freecodecamp.org/news/author/theankurtyagi/).
- Visit my [personal blog](https://theankurtyagi.com/blog/) for more tech-related articles.
Thank you for reading, and happy coding.