# Python Auth x Sharepoint

{% hint style="info" %}
Pre-requisites from [Microsoft lab sample](https://learn.microsoft.com/en-us/graph/tutorials/python?tabs=aad)

* python3 -m pip install azure-identity
* python3 -m pip install msgraph-core
  {% endhint %}

{% hint style="info" %}
Sharepoint Site Resource Type

<https://learn.microsoft.com/en-us/graph/api/resources/site?view=graph-rest-1.0>
{% endhint %}

{% hint style="info" %}
Python AZ Identity Packages (See usernamepasswordcredentials)

<https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity?view=azure-python>
{% endhint %}

```python
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())
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jianny.net/work/azure/app-registration-auths/python-auth-x-sharepoint.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
