Passwordless and OTP-less Authentication for your website. Check the documentaion here.
A step by step series of examples that tell you how to get a development env running. These instructions will let you render the form in your speicified container, and allow you to attach successful login callback for futher actions.
pip install sawo
The getContext method is used to create sawo dict object from data gain from DB in Django
from sawo import createTemplate,getContext,verifyToken
- Login to sawo dev console
- Create a new project
- Set Project Name
- Set Project Host
- For dev: point to localhost
- For prod: point to your domain.
- Copy the API key
Getting started Creating template for sawo passwordless and OTP-less Authentication for your website.
createTemplate("<filepath>")
#example
createTemplate("templates/partials")
createTemplate("./<filepath>",flask=True)
#example
createTemplate("./templates/partials",flask=True)
This will create a _sawo.html file in the filepath provided.
{% include "<filepath>/_sawo.html" %}
#example
{% include "partials/_sawo.html" %}
{% include "./<filepath>/_sawo.html" %}
#example
{% include "./partials/_sawo.html" %}
The variable name used in _sawo.html template are sawo.auth_key, sawo.identifier and sawo.to so to send that data we create a json.
Note
- The "to" route should be a post route which can recive posted data.
- If you dont know how data is passed to templates in Django or Flask, We will suggest looking into it first.
context = {
"sawo": {
"auth_key" : "<api_key>",
"identifier":"email | phone_number_sms",
"to":"<route>" #the route where you will recive the payload sent by sdk
}
}
#exapmple
context = {
"sawo": {
"auth_key" : "785ha-hdjsdsd-799-ss345",
"identifier":"phone_number_sms",
"to":"login"
}
}
Step 1. Creating fields for sawo api_key and identifier to set it from admin dashboard.
copy this code in models of your app
class Config(models.Model):
api_key = models.CharField(max_length=200)
identifier = models.CharField(max_length=100, choices=[("email","Email"),("phone_number_sms","Phone")])
Step 2. Setting up view.py of app.
Note: Route should be the reciving end where you can handle post request
from .models import Config
from sawo import getContext
def <yourfuntion>(request):
config = Config.objects.order_by('-api_key')[:1]
context = {
"sawo":getContext(config,<route>) #the route where you will recive the payload sent by sdk
}
#example
def index(request):
config = Config.objects.order_by('-api_key')[:1]
context = {
"sawo":getContext(config,"login")
}
sawo = {
"auth_key" : "<api_key>",
"identifier":"email | phone_number_sms",
"to":"<route>" #the route where you will recive the payload sent by sdk
}
#exapmple
sawo = {
"auth_key" : "785ha-hdjsdsd-799-ss345",
"identifier":"phone_number_sms",
"to":"login"
}
When the login is done on the webpage it sends the data to backend as payload to verify user, you can use verifyToken function, it returns a boolen.
from sawo import verifyToken
#use the methods provided by flask and django to recive data from post request
#then use this funtion it will return True or False depending on user status
verifyToken(payload)
//example
payload = <data from POST request>
if(verifyToken(payload)):
#do somthing
else:
#do somthing else
Django Tutorial - See Tutorial
Flask Tutorial - See Tutorial
We use SemVer for versioning.
SAWO Labs - GitHub
This project is licensed under the MIT License