Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
aad-token-verify
Readme
A python utility library to verify an Azure Active Directory OAuth token. Meant for resource servers serving secured API endpoints (eg FastAPI)
python3 -m pip install aad-token-verify
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
Feel free to submit issues and pull requests!
FAQs
A python utility library to verify an Azure Active Directory OAuth token
We found that aad-token-verify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.