Want to connect to sharepoint online , but don’t want to use a private agent? Look no further….
One of my pet-peeves with the office 365 suite is that simple stuff is really hard to get done, like authenicating to sharepoint online (or finding the right api to use). So i decided to try and convert one of my .net setups for fetching office 365 tokens to a jitterpack.
Sharepoint online has three different ways of authenticating
- Azure AD
- Sharepoint APPS
- Client credentials.
I am going to show you how to implement option 3.
How does the authentication flow work in sharepoint online?
After step 5 you will have a fedauth cookie. This cookie you will need to send with each request and will allow you to make calls to the REST endpoints available.
So how does this translate into a solution?
After running this script you have the following headers at your disposal:
- Cookie : this contains the RTFA & Fedauth token. These are needed in order to make calls to the rest interface
- X-RequestDigest ; this contains the request digest. This header is only needed if you want to make POST/PUT/MERGE/DELETE calls. Once fetched it will store it in cache until it is expire
This script runs every 5 minutes and checks if the request digest is still valid. If not it will run the complet flow again. This will ensure there is always a valid cookie & request digest
So how do you now use this magical cookies in a solution?
In the solution there is a folder named FLOWS. In there are samples how to use the LIST and DOCUMENT endpoint of sharepoint online. Both of these will run out of the box (once there is a cookie + request digest).
The endpoints used in the solution are already configured to use the request digest + cookies from cache. The only thing you need to configure are the project variables.