SharePoint: an app with a certificate#
With Application Permission (cert based), a SharePoint item acts as the app itself and proves it with a certificate. The private key stays on your server and is never sent to Microsoft; only a signature made with it is. This is the form Microsoft recommends for servers, and the one to use in production.
A certificate#
Any certificate with an RSA key will do; it does not have to come from a public authority. Make one for this purpose only, for instance with OpenSSL:
openssl req -x509 -newkey rsa:2048 -nodes -days 730 -subj "/CN=CrushMFT SharePoint" -keyout sharepoint.key -out sharepoint.cer
You get two files:
| File | For |
|---|---|
sharepoint.cer |
the certificate, public. It is uploaded to Microsoft. |
sharepoint.key |
the private key, in the text form that begins with -----BEGIN PRIVATE KEY-----. It goes into the item, and nowhere else. |
At Microsoft#
- Register an app: see The app registration. No redirect URI is needed.
- Give it an application permission of Microsoft Graph and grant admin consent. Prefer
Sites.Selectedwith a grant per site: see Only some sites. - Under Certificates & secrets, on the tab Certificates, Upload certificate and choose
sharepoint.cer. - Copy the Thumbprint that is then shown beside it.
In the item#
-
Choose the item type SharePoint and the choice Application Permission (cert based).
-
A window, "Please enter Sharepoint Oauth (Cert Based)", asks for:
Field Enter Client ID the application (client) ID Thumbprint the thumbprint from the portal Private Key the whole text of sharepoint.key, with its first and last lineTenant the directory (tenant) ID -
The item is filled in: the User name is
app_permission_cert~, the client ID,~and the thumbprint. -
Say where: paste a Shared Link, or fill in the site and library. See Where in SharePoint.
-
Press Test.
The private key is stored with the item, encrypted like the item's address. After that, delete the key file from wherever you made it, or lock it away.
The certificate expires#
On the day the certificate ends, the item stops working.
- Some weeks before, make a new certificate.
- Upload it to the app registration beside the old one. Both are accepted.
- In the item, choose Application Permission (cert based) again and enter the new thumbprint and key.
- When everything runs on the new one, remove the old certificate from the registration.
Done in this order, there is no moment without access.
When it does not work#
| What you see | Usually |
|---|---|
| "AADSTS700027: client assertion contains an invalid signature" | the private key does not belong to the uploaded certificate; or the thumbprint is of another certificate |
| the key is not accepted | it is not in the form -----BEGIN PRIVATE KEY----- (PKCS#8). Convert it: openssl pkcs8 -topk8 -nocrypt -in old.key -out sharepoint.key |
| "access denied" | no admin consent; no grant on the site with Sites.Selected |
| it stopped working | the certificate expired |