Python Auth x Sharepoint

Pre-requisites from Microsoft lab sample

  • python3 -m pip install azure-identity

  • python3 -m pip install msgraph-core

from azure.identity import UsernamePasswordCredential
from msgraph.core import GraphClient
# Using InteractiveBrowserCredential for demonstration purposes.
# There are many other options for getting an access token. See the following for more information.
# https://pypi.org/project/azure-identity/
credential = UsernamePasswordCredential(client_id='a12fd75f-2b0b-42ce-ad03-750bb62b87f0',username='RITM@nmicrosoft.com',password='ALSsgdf21',tenant_id='bc876b21-f134-4c12-a265-8ed26b7f0f3b')
client = GraphClient(credential=credential)


##################
# [0] Auth test
#       #result = client.get('/me')
# [1] Graph Explorer to test queries
#       https://developer.microsoft.com/en-us/graph/graph-explorer
# [2] Example to visit default Sharepoint site
#       https://jabil.sharepoint.com/
result = client.get('/sites/d1acf547-1324-406b-82bb-c06ecd6c5a66/lists')
##################

#result = client.get(/sites/4637ce2f-2cba-4163-a038-e5bec3826b0e/drive/items/f685c3ea-b38e-4d4b-8290-761c57c11cbe35/content)
# result = client.get('/me/drive/root')
# result = client.get('/sites/4637ce2f-2cba-4163-a038-e5bec3826b0e/lists')
# result = client.get('/sites')
# result = client.get('/sites/{site-id}/lists/{list-id}/items')
print(result.json())

Last updated