skillfed

fastapi-azure-auth

Easy and secure implementation of Azure Entra ID for your FastAPI APIs

fastapi-azure-auth v5.3.0 554.9K downloads/30d#6,030 on PyPI678
Permissive license Active released

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-auth

uv

uv add fastapi-azure-auth

poetry

poetry add fastapi-azure-auth

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software DevelopmentTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Application FrameworksTopic :: Software Development :: Libraries :: Python Modules

Tags

azure entra id fastapiazure ad authenticationfastapi oauth2 azureazure entra fastapifastapi azure authorizationazure ad fastapi securityentra id oauth2
azure-entra-idoauth2-fastapienterprise-auth

More Software Development packages