https://github.com/abhiprojectz/dj-sawo-starter
This is a ready to use SAWO passwordless authentication in Django.
https://github.com/abhiprojectz/dj-sawo-starter
django sawo-labs
Last synced: 3 months ago
JSON representation
This is a ready to use SAWO passwordless authentication in Django.
- Host: GitHub
- URL: https://github.com/abhiprojectz/dj-sawo-starter
- Owner: abhiprojectz
- Created: 2021-08-25T05:06:42.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-25T06:32:49.000Z (almost 4 years ago)
- Last Synced: 2025-01-07T21:35:02.060Z (5 months ago)
- Topics: django, sawo-labs
- Language: Python
- Homepage: https://djsawo.abhiofficial.repl.co/
- Size: 1.81 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Introduction
Before going into the tutorial, let's first know what is SAWO.
**SAWO** is an authentication system that allows users to be onboarded without the need of passwords or one-time passwords, making the process simple, quick, and safe. SAWO employs a powerful cryptography-based authenticator that outperforms OTPs, passwords, and social logins.
In simple words , SAWO lets you add a authentication system that works without passwords or OTP.
__In more simplar words__, You must have seen login forms with username & password , now that's got old. Sawo vanishes that password field in a more safe, efficient & realible way.
In one line , **Login without password.**
Okay , so now come back to our tutorial.
# What will you be getting?
A ready to plug starter Django project with **SAWO's auth ready to use**.

For instance, you may visit in any one of the below URLs.
+ **Heroku** : []()
+ **Repl** : []()
# Get Started
Let me give you a brief intro of what we will be going through in this post.
Believe me after reading this post you will be able to integrate SAWO in Django with ease.
## Requirements
Python, Django installed on your machine and creating a virtual environment would be great!
> Quick tip:
`$ python -m venv env`
`$ source env/bin/activate`
## Prerequisite
+ Create a account on sawo's dev console by [visiting here](https://dev.sawolabs.com/).
+ Now create a project in your **Sawo's dev** console.
+ After creating a project , you will have these **four things.**

+ Set you hostname , for example let say for local testing set it as `localhost`, Avoid adding any port or protocol, otherwise it will not work!
+ Copy your `API KEY` for this tutorial.## Installing Sawo
Install the sawo package using python package manager.
```
pip install sawo
```Import all the required methods which will come handy in our tutorial.
```py
createTemplate, getContext, verifyToken
```Now as instructed in the official sawo docs place this line
```
createTemplate("")
```**for example **
```
createTemplate("templates/partials")
```This will create a directory in your django project, which then afterwards you may easily include into your app's templates.
**Using below tag:**
```
{% include "partials/_sawo.html" %}
```# The Plan
+ Importing all the basic methods from django & others important packages such as json etc.
+ Basic Class based views for authentication.
+ Sending & recieving the payload.
+ Verifying the JWT tokens at the backend side.
+ Registering URL Patterns.
+ Deploying the project on heroku & repl, yes both!# What are the goals
This app will act as a boilerplate app for your next Sawo django app.
This is a ready to integrate project backed with the authentication part, which you may futher customize accordingly.# Getting things ready
Below are the steps to get it run live on your local server.
+ Clone this repo
```
git clone https://github.com/abhiprojectz/Dj-Sawo-Starter```
+ Migrate to create the DB table for storing users into database.
```
python manage.py runserver```
+ Add your API key in the `.env` file.
```
API_KEY = 76d8cca5-6b7e-4cb4-******```
+ Test it live
```
python manage.py runserver
```Great! Everything is ready to build your next web app in Django with passwordless authentication.
# Things to note
You may add the host if you wanna deploy the app somewhere.
```
ALLOWED_HOSTS = [
'127.0.0.1',
'localhost',
'__deployed_host__',
]
```> Replace `__deployed_host__` with your own host.
# Deploying on heroku
## Prerequisite
Create a [account on heroku](https://id.heroku.com/login) within a free tier.
Now visit [ Apps dashboard](https://dashboard.heroku.com/apps) and create a app
You may either connect to your gitHub repo or may use **Heroku CLI**.
Now as you have the app with you , lets add the **environment variables** , again you may use Heroku CLI or directly add via the UI.

Fine ,Now everything is ready to run.
# Deploying on Relp
Create a new repl by importing from github repo

Then create a `.replt` file and put the below:
```
language = "python3"
run = "bash main.bash"
```
Here we specify what to run in the console , like which commands.Create a file with name `main.bash `
```
pip install -r requirements.txt
python manage.py runserver 0.0.0.0:8000
```> Specifying a port on repl is a must in case of django.
Alternatevly you may just put the main command in `run` variable that is:
```
run="python manage.py runserver 0.0.0.0:8000"
```The reason for **creating a bash file** is that it will enable you to **run multiple shell commands.**
Create a pip packages lock file once
```
cat requirements.txt|xargs poetry add
```This will create a `poetry.lock` file , with all your dependencies listed.
Moreover, Poetry lock package is a simple tool to create a Python package from a Poetry project which pins down all the versions from the poetry. lock file as a dependency.# Conclusion
This is how you can intgrate SAWO's passwordless authentication into your Django project.
If this helps then U , don't forget to give it a share!
Happy Hacking !