SharePoint: an app with a client secret#
With Application Permission, a SharePoint item acts as the app itself. Nobody signs in: the server shows Microsoft the app's ID and a secret, and is let in with the rights the app was granted. This is the usual way for a server that runs unattended.
At Microsoft#
-
Register an app: see The app registration. No redirect URI is needed for this way.
-
Under API permissions, Add a permission, Microsoft Graph, Application permissions, and choose one:
Permission Gives the app Sites.Selectednothing by itself: only the sites you then grant it, see below. The one to prefer. Files.ReadWrite.Allreading and writing of all files in all sites and all OneDrives of the tenant Sites.FullControl.Alleverything in all sites, including their settings and permissions -
Press Grant admin consent. Application permissions always need it.
-
Under Certificates & secrets, make a New client secret. Copy its value at once; it is shown only then. Note when it expires.
In the item#
- Choose the item type SharePoint and the choice Application Permission.
- A window, "Please enter Sharepoint Oauth", asks for Client ID, Client Secret and Tenant. Enter the application ID, the secret's value and the tenant ID.
- The item is filled in: the User name is
app_permission~followed by the client ID, the Password is the secret. - Say where: paste a Shared Link, or fill in the site and library. See Where in SharePoint.
- Press Test.
Only some sites#
Files.ReadWrite.All opens the whole tenant to whoever holds the secret. With Sites.Selected, the app can reach only the sites an administrator names:
- Give the app the application permission
Sites.Selected, with admin consent. - For each site, an administrator of SharePoint grants the app a role on it, read, write or more. This is done with Microsoft Graph, by a request to the site's
permissions, or with the PowerShell tools for SharePoint; Microsoft describes both under "Sites.Selected". - In the item, name the site exactly: the app cannot search for sites, so use Shared Link or the site's path.
A stolen secret then opens two sites, not two thousand.
The secret expires#
A client secret has an end date, at most two years away. On that day the item stops working, for all users at once.
- Write the date down where the team sees it.
- Make the new secret some weeks before, open the item, choose Application Permission again and enter it.
- If the item uses a connection profile, you change it in one place.
A certificate is longer-lived and never travels: see An app with a certificate.
When it does not work#
| What you see | Usually |
|---|---|
| "AADSTS7000215: invalid client secret" | the secret's ID was entered instead of its value; or it expired |
| "AADSTS700016: application not found" | the client ID, or the tenant |
| "access denied" | no admin consent; a delegated permission instead of an application permission; with Sites.Selected, no grant on this site |
| it lists the site and cannot write | the app has only the role read on the site |