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

https://github.com/obaraelijah/django-2factor-authentication

Implementing 2-Factor Authentication in Django&DRF
https://github.com/obaraelijah/django-2factor-authentication

2fauth django django-rest-framework docker

Last synced: 11 months ago
JSON representation

Implementing 2-Factor Authentication in Django&DRF

Awesome Lists containing this project

README

          

# Django - DRF 2factor Authentication using an Authenticator App



Twitter: talkcoding

👋This guides how to implement two-factor authentication in Django & DRF using Authenticator Apps

Complete guide [Medium](https://medium.com/@elijahobara/django-rest-api-protection-via-2fa-two-factor-authentication-bbeab8d26100)

## Tools & Services:
- Django & DRF : for building the APIs
- Docker & Docker compose: Containerization
- PostgreSQL: Relational DB

## By the end of this tutorial
- Understand how Two-Factor Authentication (2FA) works.
- Onboard a user on the system
- Generate a QR code for the user
- Enable users to make a login attempt using valid credentials, such as their email and password.
- Authenticate the user using an offline OTP generated by an Authenticator App.

## Running locally

Create a .env file by copying the .env.sample provided and run:
```
docker compose build && docker compose up
```
to start the container. As an alternative, run:
```
docker-compose -f docker-compose.dev.yml up --build
```
to build and run the container using the dev yaml file.
Make sure to externalize the db instance to be used. It can be in another container.

## Run tests
Run descriptive tests in the container using:
```
docker compose exec pytest -rP -vv
```

Access the docs on:

```
http://localhost:8000/api/v1/doc
```

# Doc
![Screenshot](screenshot1.png)

# QR code
![Screenshot](screenshot2.png)

# Test
![Screenshot](screenshot3.png)