fastapi-azure-auth
Easy and secure implementation of Azure Entra ID for your FastAPI APIs
What it is and what it does
FastAPI-Azure-Auth integrates Azure Entra ID authentication into FastAPI applications, eliminating the need to build OAuth2 token validation and authorization logic from scratch. It supports single-tenant, multi-tenant, and B2C authentication flows, with scope-based access control and tenant validation. The package wraps FastAPI's OAuth2 security scheme and handles OpenID Connect discovery, token validation via cryptography and pyjwt, and provides Swagger UI integration for interactive authentication during development.
The package depends on fastapi, pydantic for configuration, httpx2 for HTTP calls, cryptography and pyjwt for token verification, and anyio for async operations. Setup involves registering an Azure application, configuring FastAPI with OAuth2 redirect settings, and instantiating the appropriate bearer scheme (SingleTenant, MultiTenant, or B2C) as a dependency. Once configured, routes can enforce authentication and specific scopes declaratively.
Use it for:
- Protect FastAPI APIs with Azure Entra ID in enterprise environments where Azure is the identity provider.
- Build multi-tenant SaaS applications that authenticate users from multiple Azure tenants with tenant isolation.
- Implement scope-based authorization to restrict API endpoints to users with specific permissions.
- Add Swagger UI authentication to FastAPI OpenAPI documentation for testing authenticated endpoints interactively.
- Migrate existing Azure AD authentication from other frameworks to FastAPI without rewriting auth logic.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds Azure Entra ID (formerly Azure AD) authentication and authorization to FastAPI applications, handling OAuth2 token validation and scope-based access control.
Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and directly solves a common enterprise requirement. If your FastAPI application needs Azure Entra ID authentication, this is a purpose-built solution that handles the OAuth2 and token validation details. Install it if you are deploying to an Azure-centric organization; skip it if you use a different identity provider.
Install
fastapi-azure-auth on PyPI
pip
pip install fastapi-azure-authuv
uv add fastapi-azure-authpoetry
poetry add fastapi-azure-authInstalling fastapi-azure-auth
Before you install
Low install friction with a pure Python wheel. Actively maintained with a recent release (43 days old) and 678 repository stars. Supports current Python versions (3.11–3.14).
License in practice
MIT license permits commercial and private use with minimal restrictions, making it suitable for enterprise deployments.
Quickstart
pip install fastapi-azure-auth
from fastapi_azure_auth.auth import SingleTenantAzureAuthorizationCodeBearer
azure_scheme = SingleTenantAzureAuthorizationCodeBearer(
app_client_id='your-client-id',
tenant_id='your-tenant-id',
scopes={'api://your-client-id/user_impersonation': 'user_impersonation'}
)
Requires Azure Entra ID tenant and application registration; OAuth2 configuration in FastAPI app must include swagger_ui_oauth2_redirect_url and swagger_ui_init_oauth.
Verify before relying
- Whether token caching or refresh-token handling is built in or requires custom implementation.
- Support for custom claim validation beyond standard OpenID Connect claims.
- Performance characteristics under high-concurrency workloads.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — anyio, cryptography, fastapi, httpx2, pydantic, pyjwt |
| Maintenance | actively maintained — 43 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 554,887/month — #6,030 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: fastapi_azure_auth-5.3.0-py3-none-any.whl
Keywords: ad, async, asyncio, authentication, azure, azure ad, azure entra, azure entra id, azuread, entra id, fastapi, multi tenant, oauth2, oidc, security, single tenant, starlette, trio
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
identityProvides a high-level authentication and…
permissive · top 15,000 on PyPI
axioms-fastapiAdds OAuth2/OIDC JWT token validation and…
permissive · top 15,000 on PyPI
fastapi-auth0Integrates Auth0 authentication into FastAPI…
permissive · top 15,000 on PyPI
msalMSAL for Python handles OAuth2 and OpenID…
permissive · top 1,000 on PyPI
azure-identityProvides Microsoft Entra ID token-based…
unclear · top 1,000 on PyPI
fastapi-keycloak-middlewareFastAPI middleware that integrates Keycloak for…
unclear · top 15,000 on PyPI
redis-entraidProvides Entra ID (Azure Active Directory)…
unclear · top 5,000 on PyPI
fastapi-cloudauthIntegrates FastAPI applications with cloud…
permissive · top 15,000 on PyPI
fastapi-cliFastAPI CLI is a command-line tool that runs…
permissive · top 1,000 on PyPI
cadwynCadwyn generates older API versions…
permissive · top 5,000 on PyPI