WhatsApp OTP authentication for Python apps (Flask, Django, FastAPI)
Project description
markdown
Celonix OTP - Python
WhatsApp OTP authentication for Python applications.
Works with Flask, Django, FastAPI, or any Python framework.
Install
pip install celonix-otp
Usage
python
from celonix_otp import CelonixOTP
otp = CelonixOTP()
# Send OTP
request_id = otp.send_otp("919876543210", "https://myapp.com")
print(f"OTP sent! Request ID: {request_id}")
# Verify OTP
is_valid = otp.verify_otp(request_id, "472891")
if is_valid:
print("Login successful!")
else:
print("Wrong OTP")
Flask Example
python
from flask import Flask, request, jsonify
from celonix_otp import CelonixOTP
app = Flask(__name__)
otp = CelonixOTP()
@app.route("/send-otp", methods=["POST"])
def send_otp():
phone = request.json.get("phone")
origin = request.headers.get("Origin", "")
try:
request_id = otp.send_otp(phone, origin)
return jsonify({"request_id": request_id, "status": "sent"})
except Exception as e:
return jsonify({"error": str(e)}), 400
@app.route("/verify-otp", methods=["POST"])
def verify_otp():
request_id = request.json.get("request_id")
otp_code = request.json.get("otp")
try:
is_valid = otp.verify_otp(request_id, otp_code)
return jsonify({"verified": is_valid})
except Exception as e:
return jsonify({"error": str(e)}), 400
if __name__ == "__main__":
app.run(debug=True)
Django Example
python
# views.py
from django.http import JsonResponse
from celonix_otp import CelonixOTP
otp = CelonixOTP()
def send_otp_view(request):
phone = request.POST.get("phone")
origin = request.META.get("HTTP_ORIGIN", "")
try:
request_id = otp.send_otp(phone, origin)
return JsonResponse({"request_id": request_id})
except Exception as e:
return JsonResponse({"error": str(e)}, status=400)
def verify_otp_view(request):
request_id = request.POST.get("request_id")
otp_code = request.POST.get("otp")
try:
is_valid = otp.verify_otp(request_id, otp_code)
return JsonResponse({"verified": is_valid})
except Exception as e:
return JsonResponse({"error": str(e)}, status=400)
FastAPI Example
python
from fastapi import FastAPI, Request
from celonix_otp import CelonixOTP
app = FastAPI()
otp = CelonixOTP()
@app.post("/send-otp")
async def send_otp(request: Request):
data = await request.json()
origin = request.headers.get("origin", "")
request_id = otp.send_otp(data["phone"], origin)
return {"request_id": request_id}
@app.post("/verify-otp")
async def verify_otp(data: dict):
is_valid = otp.verify_otp(data["request_id"], data["otp"])
return {"verified": is_valid}
Need Domain Whitelisting?
Send your website URL to admin@celonix.in
text
Save the file.
Tell me when done.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
celonix_otp-1.0.0.tar.gz
(3.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file celonix_otp-1.0.0.tar.gz.
File metadata
- Download URL: celonix_otp-1.0.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22d7a2cf19b41847d2ebccb54c1ffc83e17ae63d0c1337bc0e441f15abef6c7e
|
|
| MD5 |
3f2a891a11ec1f417e23aa868006236c
|
|
| BLAKE2b-256 |
b3ea1bf69765a7375935f7b8ad1fb208b1acccff499dee1a55d5bfdcb3ecd52c
|
File details
Details for the file celonix_otp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: celonix_otp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30effe15e966ddd997273abd38ea63263bac683fe9aaeac4736a3f2a7ad7dc3a
|
|
| MD5 |
7d9658b1cb9aa5107c18668c0cab2eae
|
|
| BLAKE2b-256 |
e586a6aea9ee987afa8da0d51c76c2a39bcc6534b693024449694112656195d3
|