Created
October 12, 2023 16:03
-
-
Save isvargasmsft/8a68ab21eea974e11330d6f30d8fafec to your computer and use it in GitHub Desktop.
Python simple initialization
This file contains 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
import asyncio | |
from azure.identity.aio import ClientSecretCredential | |
from msgraph import GraphServiceClient | |
credential = ClientSecretCredential( | |
'tenant_id', | |
'client_id', | |
'client_secret' | |
) | |
scopes = ['https://graph.microsoft.com/.default'] | |
client = GraphServiceClient(credentials=credential, scopes=scopes) | |
# GET /users/{id | userPrincipalName} | |
async def get_user(): | |
user = await client.users.by_user_id('userPrincipalName').get() | |
if user: | |
print(user.display_name) | |
asyncio.run(get_user()) |
This file contains 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
# Example using sync credentials and delegated access. | |
from azure.identity import DeviceCodeCredential | |
from msgraph import GraphServiceClient | |
credential=DeviceCodeCredential( | |
'CLIENT_ID', | |
'TENANT_ID', | |
) | |
scopes = ['User.Read', 'Mail.Read'] | |
client = GraphServiceClient(credentials=credential, scopes=scopes) | |
# GET /me | |
async def me(): | |
me = await client.me.get() | |
if me: | |
print(me.display_name) | |
asyncio.run(me()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment