Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tcitry/django-api-permission
A Django api permission manager that helps you custom api url in regular expression and control access.
https://github.com/tcitry/django-api-permission
api django permissions
Last synced: 2 months ago
JSON representation
A Django api permission manager that helps you custom api url in regular expression and control access.
- Host: GitHub
- URL: https://github.com/tcitry/django-api-permission
- Owner: tcitry
- License: mit
- Created: 2020-01-08T08:22:19.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-05T06:42:03.000Z (over 4 years ago)
- Last Synced: 2024-09-19T08:19:39.814Z (4 months ago)
- Topics: api, django, permissions
- Language: Python
- Homepage:
- Size: 458 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Django-API-Permission
![](https://img.shields.io/pypi/v/django-api-permission.svg?label=django-api-permission)
## 1. Intro
A Django api permission manager that helps you custom api url in regular expression and control access.
## 2. Quick Start
### 2.1 Install
```
pip install django-api-permission
```### 2.2 add to INSTALLED_APPS and MIDDLEWARE
```python
INSTALLED_APPS = [
...
'api_permission',
...
]MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
...
'api_permission.middleware.APIPermCheckMiddleware',
]
```### 2.3 migrate
```
./manage.py migrate api_permission
```### 2.4 settings
set `API_PERMISSION_CONF` in your settings.py as a dict.
```python
API_PERMISSION_CONF = {
'API_PREFIX': ['api/topic/'], # default is /
'PERMISSION_DENIED_CODE': 1, # default is 1
'AUTHORIZATION_HEADER': 'HTTP_AUTHORIZATION', # default is HTTP_AUTHORIZATION
'ADMIN_SITE_PATH': '/admin/', # default is /admin/
'TOKEN_EXPIRE': 15, # unit is days, default is None, which won't check token expire.
}
```You can custom `API_PREFIX` as a str like `'/'` or list like `['api/account', 'api/topic']`.
**When you set `TOKEN_EXPIRE`, you need add below in your `REST_FRAMEWORK` settings.**
```python
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
...
'api_permission.authentication.ExpireTokenAuthentication',
),
}
```## 3. Demo
### 3.1 list
![](./demo/demo1.png)
### 3.2 edit
![](./demo/demo2.png)
### 3.3 result
![](./demo/demo3.png)