-
-
Notifications
You must be signed in to change notification settings - Fork 335
/
auth_client_certificate_private_key.py
36 lines (29 loc) · 1.18 KB
/
auth_client_certificate_private_key.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Prerequisites:
Setting up an Azure AD app for app-only access:
- create a self signed certificate
- register an Azure AD application in the Azure Active Directory tenant that is linked to your Office 365 tenant
- grant the permissions once application is registered, for instance choose:
SharePoint
Application permissions
Sites
Sites.FullControl.All
- and finally upload the certificate to the application
Refer this article for a detailed instruction:
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azuread
"""
import os
from office365.sharepoint.client_context import ClientContext
from tests import test_cert_thumbprint, test_client_id, test_site_url, test_tenant
cert_path = "{0}/../selfsignkey.pem".format(os.path.dirname(__file__))
with open(cert_path, "r") as f:
private_key = open(cert_path).read()
cert_credentials = {
"tenant": test_tenant,
"client_id": test_client_id,
"thumbprint": test_cert_thumbprint,
"private_key": private_key,
}
ctx = ClientContext(test_site_url).with_client_certificate(**cert_credentials)
current_web = ctx.web.get().execute_query()
print("{0}".format(current_web.url))