Registry / auth-security / axioms-fastapi

axioms-fastapi

JSON →
library0.0.13pypypi✓ verified 84d ago

axioms-fastapi provides robust OAuth2/OIDC authentication and authorization for FastAPI APIs, simplifying integration with identity providers. It is currently at version 0.0.13 and sees minor, incremental releases, indicating active development with potential for API changes.

pip install axioms-fastapi
INSTALL
IMPORT
SIG · AXIOMS-FASTAPI
A
axioms-fastapi
auth-securitypythonv0.0.13
Install
5.2s avg
Import
Disk
56MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.13 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 50.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 5.2s · import 0.000s · 67MB
56MB installed
● package 56MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

init_axioms
from axioms_fastapi import init_axioms
from axioms_fastapi import OIDCConfig
require_auth
from axioms_fastapi import require_auth
AccessTokenMiddleware
from axioms_fastapi import AccessTokenMiddleware

This quickstart demonstrates how to set up a FastAPI application with `axioms-fastapi` for OIDC authentication. It configures the OIDC provider using environment variables, initializes `AxiomsAuth`, and protects an endpoint using `Depends(axioms_auth.get_current_user)`. A public endpoint is also included for comparison. Remember to replace placeholder URLs and credentials with your actual OIDC provider details.

import os from fastapi import FastAPI, Depends, HTTPException, status from axioms_fastapi import OIDCConfig, AxiomsAuth app = FastAPI() # Configure OIDC using environment variables for sensitive data # Replace with your actual OIDC provider details oidc_config = OIDCConfig( issuer_url=os.environ.get('OIDC_ISSUER_URL', 'https://your-oidc-provider.com/realm'), client_id=os.environ.get('OIDC_CLIENT_ID', 'your-client-id'), client_secret=os.environ.get('OIDC_CLIENT_SECRET', 'your-client-secret'), audience=os.environ.get('OIDC_AUDIENCE', 'api://your-app') # Often the client_id or a specific identifier ) # Initialize AxiomsAuth with the OIDC configuration axioms_auth = AxiomsAuth(oidc_config) @app.get("/protected") async def protected_route(user: dict = Depends(axioms_auth.get_current_user)): """An endpoint protected by OIDC authentication.""" # The 'user' object will contain decoded token claims if authentication is successful username = user.get('preferred_username', user.get('sub', 'anonymous')) return {"message": f"Hello, {username}! This is a protected route.", "user_info": user} @app.get("/public") async def public_route(): """A public endpoint that does not require authentication.""" return {"message": "This is a public route."} # To run this app (requires uvicorn): # 1. pip install uvicorn # 2. Set environment variables: # export OIDC_ISSUER_URL="https://your-oidc-provider.com/auth/realms/master" # Example Keycloak # export OIDC_CLIENT_ID="your_api_client_id" # export OIDC_CLIENT_SECRET="your_client_secret" # export OIDC_AUDIENCE="account" # 3. uvicorn your_file_name:app --reload # Then access /docs to try it out.
Debug
Known issues
breakingThe library is currently in `0.0.x` versions, which implies that API stability is not guaranteed. Minor version bumps (e.g., from 0.0.12 to 0.0.13) might introduce breaking changes without a major version increment.
fix
Always review the release notes and test thoroughly when upgrading to a new `0.0.x` version. Pin exact versions in `requirements.txt` to avoid unexpected breakage.
affects: <1.0.0
gotchaIncorrect OIDC configuration (e.g., `issuer_url`, `client_id`, `client_secret`, `audience`) is a common source of authentication failures. Misconfiguration can lead to `401 Unauthorized` errors or token validation issues.
fix
Carefully verify all OIDC parameters against your Identity Provider's documentation. Pay special attention to the `audience` claim, which often needs to match a specific value configured in your OIDC client or API. Use environment variables for sensitive credentials.
affects: All
gotchaIf `python-jose` fails to validate tokens with errors like 'Signature has no ECI parameter', it often indicates an issue with the public key, signing algorithm, or token structure.
fix
Ensure that your OIDC provider is correctly configured and publishing its public keys via the JWKS endpoint (usually `/.well-known/openid-configuration` provides this URL). Verify the token's signature, issuer, and audience using a JWT debugger (e.g., jwt.io).
affects: All
Upgrade
Version history
0.0.13latest on PyPI · released Nov 15, 2025
Audit
Dependencies
fastapirequiredCore web framework integration.
python-jose[cryptography]requiredJWT (JSON Web Token) handling and cryptography.
httpxrequiredAsynchronous HTTP client for OIDC discovery.
pydanticrequiredData validation and settings management (used by FastAPI internally, and often by auth libraries).
uvicornoptionalASGI server to run FastAPI applications (for quickstart/local development).
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
axioms-fastapi — pip install axioms-fastapi · libregistry