afri-auth-sms 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: afri-auth-sms
3
+ Version: 0.1.0
4
+ Summary: Plug and play OTP authentication for African telecom providers
5
+ Author: AdamKatani
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/AdamMashaka/africastalking-kit-sms
8
+ Project-URL: Repository, https://github.com/AdamMashaka/africastalking-kit-sms
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: fastapi
12
+ Requires-Dist: uvicorn
13
+ Requires-Dist: redis
14
+ Requires-Dist: africastalking
15
+ Requires-Dist: python-dotenv
16
+ Requires-Dist: typer
17
+
18
+ # Afri Auth SMS
19
+
20
+ Plug-and-play SMS OTP authentication package for FastAPI and Africa's Talking.
21
+
22
+ ## Installation
23
+
24
+ pip install afri-auth-sms
25
+
26
+ ## Usage
27
+
28
+ from afri_auth import OTPAuth
@@ -0,0 +1,11 @@
1
+ # Afri Auth SMS
2
+
3
+ Plug-and-play SMS OTP authentication package for FastAPI and Africa's Talking.
4
+
5
+ ## Installation
6
+
7
+ pip install afri-auth-sms
8
+
9
+ ## Usage
10
+
11
+ from afri_auth import OTPAuth
@@ -0,0 +1 @@
1
+ from .otp import OTPAuth
@@ -0,0 +1,21 @@
1
+ import typer
2
+ import shutil
3
+ from pathlib import Path
4
+
5
+ app = typer.Typer()
6
+
7
+
8
+ @app.command()
9
+ def init(project_name: str = "starter_project"):
10
+
11
+ source = Path(__file__).parent / "templates"
12
+ destination = Path(project_name)
13
+
14
+ destination.mkdir(exist_ok=True)
15
+
16
+ shutil.copy(
17
+ source / "fastapi_app.py",
18
+ destination / "main.py"
19
+ )
20
+
21
+ typer.echo(f"Project '{project_name}' created successfully!")
@@ -0,0 +1,12 @@
1
+ import os
2
+ from dotenv import load_dotenv
3
+
4
+ load_dotenv()
5
+
6
+ AFRICASTALKING_USERNAME = os.getenv("AFRICASTALKING_USERNAME")
7
+ AFRICASTALKING_API_KEY = os.getenv("AFRICASTALKING_API_KEY")
8
+
9
+ REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
10
+ REDIS_PORT = int(os.getenv("REDIS_PORT", 6379))
11
+
12
+ OTP_EXPIRY = int(os.getenv("OTP_EXPIRY", 300))
@@ -0,0 +1 @@
1
+ from .router import router as OTPRouter
@@ -0,0 +1,29 @@
1
+ from fastapi import APIRouter
2
+ from pydantic import BaseModel
3
+ from afri_auth.otp import OTPAuth
4
+
5
+ router = APIRouter()
6
+
7
+ otp_auth = OTPAuth()
8
+
9
+
10
+ class SendOTPRequest(BaseModel):
11
+ phone: str
12
+
13
+
14
+ class VerifyOTPRequest(BaseModel):
15
+ phone: str
16
+ code: str
17
+
18
+
19
+ @router.post("/send-otp")
20
+ async def send_otp(data: SendOTPRequest):
21
+ return await otp_auth.send_otp(data.phone)
22
+
23
+
24
+ @router.post("/verify-otp")
25
+ async def verify_otp(data: VerifyOTPRequest):
26
+ return await otp_auth.verify_otp(
27
+ data.phone,
28
+ data.code
29
+ )
@@ -0,0 +1,49 @@
1
+ from .security import generate_otp
2
+ from .storage import redis_client
3
+ from .providers.africastalking import send_sms
4
+ from .config import OTP_EXPIRY
5
+
6
+
7
+ class OTPAuth:
8
+
9
+ async def send_otp(self, phone: str):
10
+
11
+ code = generate_otp()
12
+
13
+ redis_client.setex(
14
+ f"otp:{phone}",
15
+ OTP_EXPIRY,
16
+ code
17
+ )
18
+
19
+ message = f"Your OTP code is {code}"
20
+
21
+ await send_sms(phone, message)
22
+
23
+ return {
24
+ "success": True,
25
+ "message": "OTP sent successfully"
26
+ }
27
+
28
+ async def verify_otp(self, phone: str, code: str):
29
+
30
+ stored_code = redis_client.get(f"otp:{phone}")
31
+
32
+ if not stored_code:
33
+ return {
34
+ "success": False,
35
+ "message": "OTP expired"
36
+ }
37
+
38
+ if stored_code != code:
39
+ return {
40
+ "success": False,
41
+ "message": "Invalid OTP"
42
+ }
43
+
44
+ redis_client.delete(f"otp:{phone}")
45
+
46
+ return {
47
+ "success": True,
48
+ "message": "OTP verified successfully"
49
+ }
@@ -0,0 +1,29 @@
1
+ from afri_auth.config import AFRICASTALKING_USERNAME
2
+ import africastalking
3
+
4
+ # from afri_auth.config import (
5
+ # AFRICASTALKING_USERNAME,
6
+ # AFRICASTALKING_API_KEY
7
+ )
8
+
9
+ def get_sms_client():
10
+
11
+ africastalking.initialize(
12
+ AFRICASTALKING_USERNAME,
13
+ AFRICASTALKING_API_KEY
14
+ )
15
+
16
+ return africastalking.SMS
17
+ sms = africastalking.SMS
18
+
19
+
20
+ async def send_sms(phone, message):
21
+
22
+ sms = get_sms_client()
23
+
24
+ response = sms.send(
25
+ message,
26
+ [phone]
27
+ )
28
+
29
+ return response
@@ -0,0 +1,4 @@
1
+ import random
2
+
3
+ def generate_otp():
4
+ return str(random.randint(100000, 999999))
@@ -0,0 +1,8 @@
1
+ import redis
2
+ from .config import REDIS_HOST, REDIS_PORT
3
+
4
+ redis_client = redis.Redis(
5
+ host=REDIS_HOST,
6
+ port=REDIS_PORT,
7
+ decode_responses=True
8
+ )
@@ -0,0 +1,17 @@
1
+ from fastapi import FastAPI
2
+ from afri_auth.fastapi import OTPRouter
3
+
4
+ app = FastAPI()
5
+
6
+ app.include_router(
7
+ OTPRouter,
8
+ prefix="/auth",
9
+ tags=["Authentication"]
10
+ )
11
+
12
+
13
+ @app.get("/")
14
+ def home():
15
+ return {
16
+ "message": "Afri Auth Running"
17
+ }
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: afri-auth-sms
3
+ Version: 0.1.0
4
+ Summary: Plug and play OTP authentication for African telecom providers
5
+ Author: AdamKatani
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/AdamMashaka/africastalking-kit-sms
8
+ Project-URL: Repository, https://github.com/AdamMashaka/africastalking-kit-sms
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: fastapi
12
+ Requires-Dist: uvicorn
13
+ Requires-Dist: redis
14
+ Requires-Dist: africastalking
15
+ Requires-Dist: python-dotenv
16
+ Requires-Dist: typer
17
+
18
+ # Afri Auth SMS
19
+
20
+ Plug-and-play SMS OTP authentication package for FastAPI and Africa's Talking.
21
+
22
+ ## Installation
23
+
24
+ pip install afri-auth-sms
25
+
26
+ ## Usage
27
+
28
+ from afri_auth import OTPAuth
@@ -0,0 +1,18 @@
1
+ README.md
2
+ pyproject.toml
3
+ afri_auth/__init__.py
4
+ afri_auth/cli.py
5
+ afri_auth/config.py
6
+ afri_auth/otp.py
7
+ afri_auth/security.py
8
+ afri_auth/storage.py
9
+ afri_auth/fastapi/__init__.py
10
+ afri_auth/fastapi/router.py
11
+ afri_auth/providers/africastalking.py
12
+ afri_auth/template/fastapi_app.py
13
+ afri_auth_sms.egg-info/PKG-INFO
14
+ afri_auth_sms.egg-info/SOURCES.txt
15
+ afri_auth_sms.egg-info/dependency_links.txt
16
+ afri_auth_sms.egg-info/entry_points.txt
17
+ afri_auth_sms.egg-info/requires.txt
18
+ afri_auth_sms.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ afri-auth-sms = afri_auth.cli:app
@@ -0,0 +1,6 @@
1
+ fastapi
2
+ uvicorn
3
+ redis
4
+ africastalking
5
+ python-dotenv
6
+ typer
@@ -0,0 +1 @@
1
+ afri_auth
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "afri-auth-sms"
7
+ version = "0.1.0"
8
+ description = "Plug and play OTP authentication for African telecom providers"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = {text = "MIT"}
12
+
13
+ authors = [
14
+ {name = "AdamKatani"}
15
+ ]
16
+
17
+ dependencies = [
18
+ "fastapi",
19
+ "uvicorn",
20
+ "redis",
21
+ "africastalking",
22
+ "python-dotenv",
23
+ "typer"
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/AdamMashaka/africastalking-kit-sms"
28
+ Repository = "https://github.com/AdamMashaka/africastalking-kit-sms"
29
+
30
+ [project.scripts]
31
+ afri-auth-sms = "afri_auth.cli:app"
32
+
33
+ [tool.setuptools.packages.find]
34
+ include = ["afri_auth*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+