Catalog PyPI
Back to packageRELEASE DETAILS

0.0.1

PyPI

aad-token-verify-kbr

Forked: A python utility library to verify an Azure Active Directory OAuth token

adazurejwtoauthtokenverify
Published1 Aug 2023
Direct dependencies0
Transitive dependenciesNot calculated

README

Version 0.0.1 documentation

Tests PyPi

aad-token-verify

A python utility library to verify an Azure Active Directory OAuth token. Meant for resource servers serving secured API endpoints (eg FastAPI)

Install

python3 -m pip install aad-token-verify

Usage

To use stand alone, simply import the verify payload function and call.

from aad_token_verify import get_verified_payload

token_verifier = get_verified_payload(token, tenant_id="YOUR_TENANT_ID", audience_uris=["AUDIENCE_URI"])

To use with FastAPI, there's some setup to get the Swagger docs to work

from fastapi import Depends, FastAPI
from fastapi.openapi.models import OAuthFlowImplicit, OAuthFlows
from fastapi.middleware.cors import CORSMiddleware
from fastapi.security import OAuth2

from aad_token_verify import get_verified_payload

# TODO Update these with your Tenant ID, Audience URI, and Client ID
_TENANT_ID = "ISSUER_TENANT_ID"
_AUDIENCE_URI = "https://YOUR_AUDIENCE_URI"
_AAD_CLIENT_ID = "CLIENT_ID"

oauth2_scheme = OAuth2(
    flows=OAuthFlows(
        implicit=OAuthFlowImplicit(
            authorizationUrl=f"https://login.microsoftonline.com/{_TENANT_ID}/oauth2/v2.0/authorize",
            scopes={
                f"{_AUDIENCE_URI}/.default": "Custom Audience URI scope",
                "openid": "OpenID scope",
                "profile": "Profile scope",
                "email": "email scope",
            },
        )
    )
)

async def get_current_user(
    auth_header: str = Depends(oauth2_scheme),  # noqa: B008
):
    scheme, _, token = auth_header.partition(" ")
    return get_verified_payload(
        token,
        tenantId=_TENANT_ID,
        audience_uris=[_AUDIENCE_URI],
    )

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.swagger_ui_init_oauth = {
    "usePkceWithAuthorizationCodeGrant": True,
    "clientId": _AAD_CLIENT_ID,
    "scopes": [f"{_AUDIENCE_URI}.default"],
}

@app.get("/")
async def secured_endpoint(user=Depends(get_current_user)):
    return user

Contributing

Feel free to submit issues and pull requests!

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 0

Native requirements
0 direct targetsNot calculated transitive count
No declared dependencies in this collected response

Declarations describe requirements; they are not a resolved dependency graph.

Distribution files

1 collected
aad-token-verify-kbr-0.0.1.tar.gz

sdist · 4.98 KB · Python source

Source file

Repository

ACCESSIBLE
generalmills/azure-ad-token-verify

Shared repository data · GitHub

License detected in repository
MIT
License branch / ref
main
Last push
23 May 2024
Archived
No
Contributor identities
— · partial collection

Public sponsor counts have not been collected. These signals belong to the repository owner.

Downloads & popularity

7count
Gauge · observed snapshots24 Oct 2026
73.50
2026-10-24: 7 · observed 2026-10-24T13:45:49.7463339Z
24 Oct24 Oct

github · 1 observations shown. Missing days are unknown.

View observed values
Date / source periodValueObserved at
2026-10-2472026-10-24T13:45:49.7463339Z

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 16:54 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:8ebc95ec9f78b6e0dd81f3b855daebe57f51f0bb5367c9cc5bbecb220ca616a7

Other collected versions

View all collected versions →