Skip to content

Instantly share code, notes, and snippets.

@kozmer
Created December 19, 2025 00:44
Show Gist options
  • Select an option

  • Save kozmer/14a293a8f1c554d6778f29a7196527da to your computer and use it in GitHub Desktop.

Select an option

Save kozmer/14a293a8f1c554d6778f29a7196527da to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
import requests
tenant = (
sys.argv[1]
if len(sys.argv) > 1
else sys.exit(f"usage: {sys.argv[0]} <tenant_id or domain>")
)
try:
url = f"https://accounts.accesscontrol.windows.net/{tenant}/metadata/json/1"
metadata = requests.get(url, timeout=30).json()
realm = metadata.get("realm", tenant)
if tenant != realm:
print(f"tenant: {realm}\n")
domains = set()
for entry in metadata.get("allowedAudiences", []):
domain = entry.split("@")[-1]
if "." in domain:
domains.add(domain)
for domain in domains:
print(domain)
except Exception as e:
sys.exit(f"error: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment