Skip to main content

Server-side auth primitives (OTP, sessions, Google OAuth) with Redis

Project description

simple-auth-server

Async Python server primitives for auth flows. This package provides Redis-backed OTP and session services plus a Google OAuth auth-code exchange helper, while leaving framework integration, persistence, messaging, and token minting to your application.

Best For

  • FastAPI or other async Python backends
  • OTP onboarding flows backed by Redis
  • Google auth-code exchange handled on the server

Install

pip install simple-auth-server

For local development from this repo:

pip install -e packages/simple-auth-server-python

Quick Start

from simple_auth_server.redis_client import create_redis_client
from simple_auth_server.otp import OtpService
from simple_auth_server.session import AuthSessionService
from simple_auth_server.oauth_google import GoogleOAuthService, GoogleOAuthConfig

redis = create_redis_client()

otp_service = OtpService(redis=redis, env="development")
session_service = AuthSessionService(redis=redis)
google_oauth = GoogleOAuthService(GoogleOAuthConfig(
    client_id="your-client-id",
    client_secret="your-client-secret",
))

What It Includes

Redis Helpers

  • create_redis_client(url=None)
  • with_key_prefix(redis_client, key_prefix)

The Redis protocol is intentionally small so you can swap in your own compatible client if needed.

OTP Service

OtpService supports email and phone verification codes with:

  • rate limiting
  • max attempt tracking
  • fixed bypass codes for non-production use

Example:

ok, result = await otp_service.generate_email_otp("user@example.com")
if ok:
    code = result
else:
    error = result

Verification errors use these codes:

  • RATE_LIMITED
  • INVALID_CODE
  • MAX_ATTEMPTS
  • NOT_FOUND

Auth Session Service

AuthSessionService stores short-lived onboarding state in Redis.

session_id = await session_service.create_session("user@example.com")
session = await session_service.get_session(session_id)

Current methods:

  • create_session(email)
  • get_session(session_id)
  • update_session(session_id, updater)
  • delete_session(session_id)

Sessions track email verification state, phone state, and can hold additional JSON-safe onboarding metadata through update_session.

Google OAuth Service

GoogleOAuthService exchanges a Google auth code on the backend.

result = await google_oauth.exchange_auth_code(
    auth_code,
    required_scopes=["email", "profile"],
)

Successful responses include:

  • user
  • refreshToken
  • accessToken
  • idToken
  • scope
  • grantedScopes

What This Package Does Not Do

  • send email or SMS
  • define your HTTP routes
  • create your JWTs or session cookies
  • manage your database models

It is designed to be wired into your own application server.

Example App

See examples/server-python/app.py in this repo for a complete FastAPI example covering:

  • email OTP
  • phone OTP
  • Google OAuth
  • session resume
  • token refresh

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

simple_auth_server-0.3.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_auth_server-0.3.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file simple_auth_server-0.3.1.tar.gz.

File metadata

  • Download URL: simple_auth_server-0.3.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for simple_auth_server-0.3.1.tar.gz
Algorithm Hash digest
SHA256 d7be9795abcdb10fd55f12544c139d54f6b18ad83422f7c565b0197f05f97bde
MD5 042fbe3054d943d01094e055cd8ba0f7
BLAKE2b-256 e38d808fc2868e943b0de06c59587ec45826cc787070f64f4e7cd54c201ee134

See more details on using hashes here.

File details

Details for the file simple_auth_server-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_auth_server-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d2acaf756e85c53fd84b329bf347aa89449960af100d1a2bcdcae983a8e3786c
MD5 3e982869425853b7b1bb609a0edb7dfd
BLAKE2b-256 fc17179fb6d1374e9c87d461c9b74f1fed8b1737af4abd3501b5ea3d7c36c20f

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