An open API service indexing awesome lists of open source software.

https://github.com/t1m4/social-network-with-jwt-authentication

Django + JWT authentication
https://github.com/t1m4/social-network-with-jwt-authentication

drf drf-yasg rest-framework-simplejwt

Last synced: 11 months ago
JSON representation

Django + JWT authentication

Awesome Lists containing this project

README

          

Overview


It's simple REST API for everyday social network.


Created using Django-Rest-Framework using JWT authentication


Basic Features:



  • User signup

  • User login

  • Post creation

  • Like post

  • Unlike post

Installation


1. Install all requirements.

`pip install requirements.txt`

2. Run tests...

`python manage.py test`

3. Add `.env` file to main and `automated_bot/` directories.

4. And if everything all right start server.

`python manage.py runserver`

Basic API Features


Post creation using POST request.

1. Sign up example.

```json
{
"username": "test",
"email": "test@example.com",
"password": "password",
"double_password": "password"
}
```

2. Login example.

```json
{
"username": "test",
"password": "password"
}
```

3. Post creation example.

```json
{
"title": "test",
"description": "I love testing!"
}
```

4. Post like/unlike example.

```json
{
"post_id": "test"
}
```

5. Analytics point example.

```curl
GET /facebook/api/analitics/?date_from=2020-02-02&date_to=2020-02-15
```

6. Activity point example.

```curl
GET /facebook/api/activity/?username=test
```
```json
{
"last_login": "2021-07-19 11:31:55",
"last_request": "2021-07-19 11:48:37"
}
```

Authentication Using JWT


1. Override default User model


2. Override default UserManager model


3. Add rest_framework_simplejwt library

```python
INSTALLED_APPS += [
'rest_framework_simplejwt'
]
```

Automated bot


1. Start bot from automated_bot/

```python async_bot.py```

2.The bot use data from `automated_bot/.env` file

```python
number_of_users=5
max_posts_per_user=7
max_likes_per_user=8
```
3. Sign Up `number_of_users` users

4. Each user creates random number of posts, but maximum `max_posts_per_user`

5. Each user randomly like `max_likes_per_user` posts

Security Tips


1. Сheck password strength


2. Add lifetime for tokens

```python
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=30),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
}
```

3. Add throttling to your views. Configure it for yourself.

```python
# settings.py
REST_FRAMEWORK = {
'DEFAULT_THROTTLE_CLASSES': [
'rest_framework.throttling.AnonRateThrottle',
'rest_framework.throttling.UserRateThrottle'
],
'DEFAULT_THROTTLE_RATES': {
'anon': '50/day',
'user': '1000/day'
}
```
```python
# views.py
class RegisterAPIView(APIView):
throttle_classes = [AnonRateThrottle]
```