Skip to main content

Sawo Python SDK

Project description

Sawo

Passwordless and OTP-less Authentication for your website. Check the documentaion here.

Installing

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.

Install the sawo package

pip install sawo

Import from Sawo createTemplate, getContext and verifyToken method from the sawo package

The getContext method is used to create sawo dict object from data gain from DB in Django

from sawo import createTemplate,getContext,verifyToken

API Key

  • 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

Setup

Getting started Creating template for sawo passwordless and OTP-less Authentication for your website.

Django
    createTemplate("<filepath>")

    #example
    createTemplate("templates/partials")
Flask
    createTemplate("./<filepath>",flask=True)

    #example
    createTemplate("./templates/partials",flask=True)

This will create a _sawo.html file in the filepath provided.

Using _sawo.html in your html files
Django
    {% include "<filepath>/_sawo.html" %}

    #example
    {% include "partials/_sawo.html" %}
Flask
    {% include "./<filepath>/_sawo.html" %}

    #example
    {% include "./partials/_sawo.html" %}
Sending data required by _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

  1. The "to" route should be a post route which can recive posted data
  2. If you dont know how data is passed to templates in Django or Flask, We will suggest looking into it first.
Django
Method 1. Sending static data
    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" 
                }
            }
Method 2. Using admin and database to save config for sawo

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")
    }
Flask
    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" 
        }

Verifying Token

When he 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.

Backend Code is ame for Django and Flask
    from sawo import verifyToken
    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
    For Example (The data key pair is an example below, these keys are returned in payload once the user is authenticated from SAWO )
    data  = {
    "user_id" : "a0aca1a0-7460-4e8e-8e46-3baf2c92423d", 
    "verification_token" : "ADdHrvkgi407qNfnAyrIVqokm3OWdKUCdj8y"
          }
    if(verifyToken(data)):
        #do something
    else:
        #do something else

Tutorials

Django Tutorial - See Tutorial
Flask Tutorial - See Tutorial

Versioning

We use SemVer for versioning.

Authors

SAWO Labs - GitHub

License

This project is licensed under the MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sawo-1.2.3.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file sawo-1.2.3.tar.gz.

File metadata

  • Download URL: sawo-1.2.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.2

File hashes

Hashes for sawo-1.2.3.tar.gz
Algorithm Hash digest
SHA256 930a13e8db7d7002b94f0632749f9533f6e97ead9bb280c38f3964a3760dcc07
MD5 80c8daf935178839b48bc7b3646dcc3b
BLAKE2b-256 81203e89c3a20259cbe9400ada44e2d0d4b22d9325f76ee2a2856c7448b36144

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page