Hi @Rahul Nair
You can call https://graph.microsoft.com/beta/users?$expand=appRoleAssignments
api endpoint to list all users of Azure ad (including guest users), custom appRoles and passwordProfile.
First, you need to grant the User.ReadWrite.All
application permission to your application, and then modify the key parameters in your script.
1.
2.
import http.client
import json
import requests
def get_token():
r = requests.post("https://login.microsoftonline.com/TenantID/oauth2/token",data={"grant_type": "client_credentials","client_secret": "xxxxxxxxxxxx","client_id": "xxxxxxxxxx","resource": "https://graph.microsoft.com"})
ret_body = r.json()
return ret_body['access_token']
token = get_token()
headers = {'Authorization': 'Bearer ' + token}
conn = http.client.HTTPSConnection('graph.microsoft.com')
conn.request("GET", '/beta/users?$expand=appRoleAssignments', "", headers)
response = conn.getresponse()
server_data = response.read()
server_data = server_data.decode('utf-8')
server_data = json.loads(server_data)
print(server_data)
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.