Skip to main content

Async Python SDK for validating Azure AD B2C access tokens

Project description

Azure AD B2C

Simplified Python SDK for verifying AD B2C-issued JWTs

Usage

import aad

token = "..." # JWT to verify
tenant = "..." # B2C tenant (as in `"{tenant}.b2clogin.com/{tenant}..."`)
app_id = "..." # ClientID of app registered in the B2C tenant
policy = "B2C_1_..." # policy (aka user flow) name

await aad.authorize(token, tenant, app_id, policy)
# {
#   "idp": "...",
#   "aud": "...",
#   ... # other JWT fields
#   ... # fields configured in B2C
# }

FastAPI dependency

pip install aad[fastapi]
from fastapi import FastAPI
import aad

Claims = aad.claims(tenant, app_id, policy)
app = FastAPI()

@app.get("...")
def get(claims: Claims):
    ...

Disclaimer

The JWT decoding part is heavily inspired by azure-ad-verify-token, but with an async interface

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aad-0.1.5.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

aad-0.1.5-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page