I need to use a Python script to upload files to a SharePoint Online site using a client credentials auth flow. I am a tenant administrator and have tried granting app-only access (as described here), as well as through Azure AD, in both cases giving full site permissions. In the case of Azure AD, I've tried authorizing through the MS Graph API, as well as the SharePoint API. In both cases, I can authenticate but cannot authorize for access to the SharePoint site.
I am able to generate a Bearer access token showing Sites.FullControl.All access. However, I either get Unsupported app only token
(in the case of using client_id/secret from Azure AD app registration) or ID3035: The request was not valid or is malformed
(in the case of in the case of using client_id/secret from app-only registration through the SharePoint admin interface).
I've also attempted to authorize via the Office365-Rest-Python-Client
, which authorizes but returns a 401 when attempting to access any site resources.
I've found some evidence in the docs that obtaining a refresh token maybe required, which may require a self-signed cert, but I've gone down so many rabbit holes that I thought I'd reach out here for any potential insight.
Bottom line, I just need to run a script that uploads a file daily to a SharePoint site without any user interaction.