-
-
Save KyMidd/1aa7b80cb1e2eb69cc3dc3798615bd6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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