Skip to content

Instantly share code, notes, and snippets.

@KyMidd

KyMidd/teams.py Secret

Created November 8, 2025 22:13
Show Gist options
  • Select an option

  • Save KyMidd/1aa7b80cb1e2eb69cc3dc3798615bd6b to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/1aa7b80cb1e2eb69cc3dc3798615bd6b to your computer and use it in GitHub Desktop.
def get_user_upn(aad_object_id, token):
response = requests.get(
f"https://graph.microsoft.com/v1.0/users/{aad_object_id}",
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
if response.ok:
user_data = response.json()
upn = user_data.get("userPrincipalName") or user_data.get("mail")
if "@" in upn:
upn = upn.split("@")[0]
return upn.lower()
return "unknown_user_id"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment