make install;

some notes to myself



File uploading under Microsoft's OAuth 2.0 authz code flow

Written on February 9, 2022

Recently, I needed a way to upload files to Microsoft SharePoint on a regular/ongoing basis. Below are my notes of how I used Microsoft’s OAuth 2.0 authorization code flow and the Microsoft Graph API to do this. Ideally, I’d have a service account for this and use the client credentials grant flow, but sometimes its just easier to work with the access the Azure admin gave you than it is to go back-and-forth. In this case, I’ve delegated permission to the app to perform the uploads under my identity. Which means, since this isn’t using a service account, this will stop working when my account is decommissioned. On the positive side, given that the refresh token’s max inactive time is 90 days, there shouldn’t be a need to regularly get a new auth code.

First, register an application at, and configure API permissions. I used Microsoft Graph->User.Read, and SharePoint->AllSites.Write and SharePoint->MyFiles.Write.

Then navigate to the below URL, sign in, and authorize the app.

Microsoft will redirect to localhost:8443/test (which does not exist). Take the “code” value from the URL and plug that into authcode. This auth code is what the code will use when requesting access/refresh tokens.

The code to create the upload session and upload the actual file is straightforward.