OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Azure get EID List with API

  • Thread starter Thread starter jmcunst
  • Start date Start date
J

jmcunst

Guest
I'm currently working on a project where I need to retrieve a list of EID users from our tenant using the Azure API. Could someone guide me on how to achieve this?

Specifically, I'm looking for detailed steps or a sample code (preferably in Python) that can help me authenticate and query the necessary endpoints to get the EID user list. Any pointers on the required permissions and configurations would also be greatly appreciated.

Thanks in advance for your help!

  • App registrations
  • Create Client secrets
  • Create Lambda Function

Code:
import os
import json
import requests
from azure.identity import ClientSecretCredential

def lambda_handler(event, context):
    tenant_id = os.environ['AZURE_TENANT_ID']
    client_id = os.environ['AZURE_CLIENT_ID']
    client_secret = os.environ['AZURE_CLIENT_SECRET']

    credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
    token = credential.get_token("https://graph.microsoft.com/.default").token
    headers = {
        'Authorization': 'Bearer ' + token,
        'Content-Type': 'application/json'
    }
    response = requests.get('https://graph.microsoft.com/v1.0/users', headers=headers)
    if response.status_code == 200:
        users = response.json()
        return {
            'statusCode': 200,
            'body': json.dumps(users)
        }
    else:
        return {
            'statusCode': response.status_code,
            'body': json.dumps({'error': 'Failed to fetch users'})
        }

I can get

Code:
{
  "statusCode": 403,
  "body": "{\"error\": \"Failed to fetch users\"}"
}
<p>I'm currently working on a project where I need to retrieve a list of EID users from our tenant using the Azure API. Could someone guide me on how to achieve this?</p>
<p>Specifically, I'm looking for detailed steps or a sample code (preferably in Python) that can help me authenticate and query the necessary endpoints to get the EID user list. Any pointers on the required permissions and configurations would also be greatly appreciated.</p>
<p>Thanks in advance for your help!</p>
<ul>
<li>App registrations</li>
<li>Create Client secrets</li>
<li>Create Lambda Function</li>
</ul>
<pre><code>import os
import json
import requests
from azure.identity import ClientSecretCredential

def lambda_handler(event, context):
tenant_id = os.environ['AZURE_TENANT_ID']
client_id = os.environ['AZURE_CLIENT_ID']
client_secret = os.environ['AZURE_CLIENT_SECRET']

credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
token = credential.get_token("https://graph.microsoft.com/.default").token
headers = {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
}
response = requests.get('https://graph.microsoft.com/v1.0/users', headers=headers)
if response.status_code == 200:
users = response.json()
return {
'statusCode': 200,
'body': json.dumps(users)
}
else:
return {
'statusCode': response.status_code,
'body': json.dumps({'error': 'Failed to fetch users'})
}

</code></pre>
<p>I can get</p>
<pre><code>{
"statusCode": 403,
"body": "{\"error\": \"Failed to fetch users\"}"
}
</code></pre>
Continue reading...
 
Top