Demo for python console app (browserless) using MSAL Authentication. Based on Python sample for Microsoft Graph.
-
Install prerequisite python packages:
pip install -r requirements.txt
-
Register an application in Azure portal.
- Select API permissions
Users.Read.All
andUsers.Readbasic.All
.
- Edit Authentication settings.
- Go to Authentication. Check the box next to
https://login.microsoftonline.com/common/oauth2/nativeclient
- Find Default client type and set it to
yes
- Modify
config.py
- Replace
'ENTER_YOUR_CLIENT_ID'
with your Application (client) ID - Replace
'ENTER_YOUR_EMAIL_ADDRESS'
with your Office 365 email address - Replace
'ENTER_YOUR_PASSWORD'
with your Office 365 password
- Run the command
python sample.py
in your terminal - Enter the email address of the person you want to search for in your organisation
- A Microsoft Graph query will be excecute to return a json object of a manager's email.
e.g.
- The query exexcuted in the backend:
https://graph.microsoft.com/v1.0/users/MiriamG@M365x214355.onmicrosoft.com/manager
- Terminal output:
If you are seeing the Authorization_RequestDenied: Insufficient privelleges to complete the operation.
error, contact your administrator and request admin consent for Users.Read.All
and Users.Readbasic.All
permissions.
In your azure portal, under Home > App Registraions > API Permissions, the permissions should look as follows: