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.2.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.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_auth_server-0.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 432bd17ff42aaf8a2a9a1f989cc4554f6d6ad48d46ca9ce028f41d6cb1dc2145
MD5 1dd1838c1b2e6c48e842ad917bb66b7d
BLAKE2b-256 c1965b2939b82eb93ea8a218afe0c7809620a6097ee366f09f7b69fc15aaf9c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_auth_server-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a5124803e0253ccd623b0e46214719ade8ebd5229a5b62c93d2441576dcc49ac
MD5 bd545f3973c1ac91c130e63c6c563c8f
BLAKE2b-256 c802094d7c7d04f4595b9eb6b6c4aa11268702dab4b55816b16d514334776ecf

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