How tomasvotava/fastapi-sso works
Project type and purpose
• Type: Python library / FastAPI plugin
• Purpose: Provide a unified SSO (OAuth2/OpenID Connect) abstraction for multiple identity providers (Google, Facebook, GitHub, Microsoft, etc.) that can be dropped into any FastAPI app.
File structure
• fastapi_sso/ – the core package
– sso/base.py – defines the abstract base client and common flows
– sso/<provider>.py – concrete subclasses for each provider (Google, Facebook, etc.)
– pkce.py – implements PKCE code challenge & verifier logic
– state.py – session/state management (storing and verifying CSRF nonces)
• examples/ – standalone scripts showing how to wire up the plugin in a FastAPI app
• docs/ & mkdocs.yml – documentation generation
• tests/ – unit tests covering providers, PKCE, base flows, race‐condition lock
• CI/CD configs – GitHub Actions workflows, code coverage, linting
Key architectural patterns
• Strategy pattern: each provider implements the same interface defined in base.py
• Context manager + async lock: ensures safe concurrent login flows
• Shared components: PKCE and state modules used by all providers
• Extensibility point: drop in a new sso/<your_provider>.py
Main components & relationships
+----------------+ +----------------------+ +----------------+
| FastAPI App & | | SSO Plugin Instance | | External IdP |
| HTTP Clients | <----> | (fastapi_sso.SSO) | <----> | (Google, FB…) |
+----------------+ +----------------------+ +----------------+
| ^ ^ ^
| | | +-- PKCE module (code_challenge)
| | +------ State module (nonce store, CSRF)
| +--------- Provider classes (Strategy subtypes)
|
v
+----------------+
| Database | (optional session store for state)
+----------------+
• The FastAPI route handler calls into the SSO plugin
• The plugin orchestrates:
a. state generation & storage
b. PKCE challenge creation
c. redirect to provider’s auth endpoint
• After callback, plugin verifies state & PKCE, exchanges code for tokens, fetches user info
• Returns an OpenID/dict object back to your app
Details
• Extensibility: highlight how a new provider class plugs into base.py
• Concurrency safety: annotate the async‐lock on the context manager
• PKCE & state flows: call out these security modules as first‐class citizens
• Test coverage & CI pipelines can be noted in an “Auxiliary” section