Python – Reading SharePoint List Delegated Application Permissions

SharePoint is a powerful platform for collaboration and document management, extensively used in organizations to streamline workflows and improve productivity.

To interact with SharePoint resources programmatically, developers often use access tokens.

In this blog, we will explore how to read SharePoint lists using delegated access tokens, which allows applications to access resources on behalf of a user, ensuring secure and controlled access.

You will find lot of code on internet mainly related to Powershell using PNP, Graph or CSOM but for python you find mostly with office 365 rest client.

I am sharing the example using standard requests library that we use for accessing any rest API application and that too with delegated permissions.

Assumption is APP is already registered in Azure AD and has following delegated permissions.


Modules required:

  • os
  • Requests – For Rest API calls
  • Json – for converting the request output to json format
  • DPAPI – For Password encryption/Decryption

Script to download:

https://github.com/VikasSukhija/Python

  • PythonSPOList.py

Now update the script variables asper your environment


Also, update the ReqTokenbody à Username parameter


Now when you will run the script it will prompt you for three things for first time only:

  1. ClientID of the Registered Application
  2. Password for the UserName (Delegated account)
  3. Secret of the Registered Application

It will store all these in encrypted form in config folder after first run:



After that python will get the access token and start reading the SharePoint online list and collect all items in Coll_listItems list.

You can enhance this code further and do whatever operations you want to perform on the list items.

I just want to show how we can deal with SharePoint list using delegated tokens.

 

 

Thanks for reading and downloading…

Tech Wizard

 

https://techwizard.cloud

https://syscloudpro.com/

PowerShell Fast Track


Leave a comment