Documentation Index
Fetch the complete documentation index at: https://gofastmcp.com/llms.txt
Use this file to discover all available pages before exploring further.
fastmcp.server.auth.providers.azure
Azure (Microsoft Entra) OAuth provider for FastMCP.
This provider implements Azure/Microsoft Entra ID OAuth authentication
using the OAuth Proxy pattern for non-DCR OAuth flows.
Functions
EntraOBOToken
scopes: The scopes to request for the downstream API. For Microsoft Graph, use scopes like [“https://graph.microsoft.com/Mail.Read”] or [“https://graph.microsoft.com/.default”].
- A dependency that resolves to the downstream API access token string
ImportError: If fastmcp[azure] is not installedRuntimeError: If no access token is available, provider is not Azure, or OBO exchange fails
Classes
AzureProvider
Azure (Microsoft Entra) OAuth provider for FastMCP.
This provider implements Azure/Microsoft Entra ID authentication using the
OAuth Proxy pattern. It supports both organizational accounts and personal
Microsoft accounts depending on the tenant configuration.
Scope Handling:
- required_scopes: Provide unprefixed scope names (e.g., [“read”, “write”]) → Automatically prefixed with identifier_uri during initialization → Validated on all tokens and advertised to MCP clients
- additional_authorize_scopes: Provide full format (e.g., [“User.Read”]) → NOT prefixed, NOT validated, NOT advertised to clients → Used to request Microsoft Graph or other upstream API permissions
- OAuth proxy to Azure/Microsoft identity platform
- JWT validation using tenant issuer and JWKS
- Supports tenant configurations: specific tenant ID, “organizations”, or “consumers”
- Custom API scopes and Microsoft Graph scopes in a single provider
- Create an App registration in Azure Portal
- Configure Web platform redirect URI: http://localhost:8000/auth/callback (or your custom path)
- Add an Application ID URI under “Expose an API” (defaults to api://)
- Add custom scopes (e.g., “read”, “write”) under “Expose an API”
- Set access token version to 2 in the App manifest: “requestedAccessTokenVersion”: 2
- Create a client secret
- Get Application (client) ID, Directory (tenant) ID, and client secret
from_b2c
tenant_name and policy_name, then delegates to the standard
constructor. Returns a plain AzureProvider instance.
B2C issuer validation is disabled by default (token_issuer=None)
because B2C issuers embed the tenant GUID. Pass an explicit
token_issuer string once you know the real iss value.
Azure AD B2C does not support OBO.
Args:
tenant_name: Short B2C tenant name without.onmicrosoft.com(e.g."mytenant").policy_name: User-flow or custom-policy name (e.g."B2C_1_susi").client_id: Application (client) ID from the B2C app registration.client_secret: Client secret from the B2C app registration.required_scopes: Custom API scope names without prefix (e.g.["mcp-access"]).base_url: Public base URL of this server.custom_domain: Custom domain for the B2C authority (e.g."auth.mycompany.com"). Defaults to{tenant_name}.b2clogin.com.identifier_uri: Application ID URI. Defaults tohttps\://{tenant_name}.onmicrosoft.com/{client_id}.token_issuer: Expectedissclaim.None(default) disables issuer validation.**kwargs: Forwarded toAzureProvider.__init__.
authorize
client: OAuth client informationparams: Authorization parameters from the client
- Authorization URL to redirect the user to Azure AD
get_obo_credential
user_assertion: The user’s access token to exchange via OBO.
- A configured OnBehalfOfCredential ready for get_token() calls.
NotImplementedError: If OBO is not supported (e.g. Azure AD B2C).ImportError: If azure-identity is not installed (requires fastmcp[azure]).
close_obo_credentials
AzureJWTVerifier
JWT verifier pre-configured for Azure AD / Microsoft Entra ID.
Auto-configures JWKS URI, issuer, audience, and scope handling from your
Azure app registration details. Designed for Managed Identity and other
token-verification-only scenarios where AzureProvider’s full OAuth proxy
isn’t needed.
Handles Azure’s scope format automatically:
- Validates tokens using short-form scopes (what Azure puts in
scpclaims) - Advertises full-URI scopes in OAuth metadata (what clients need to request)
scopes_supported
read) in the scp
claim, but clients must request full URI scopes (e.g.,
api://client-id/read) from the Azure authorization endpoint. This
property returns the full-URI form for OAuth metadata while
required_scopes retains the short form for token validation.
