forked from vgrem/office365-rest-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect_with_client_certificate_adal.py
More file actions
29 lines (24 loc) · 1.01 KB
/
connect_with_client_certificate_adal.py
File metadata and controls
29 lines (24 loc) · 1.01 KB
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
import os
from office365.runtime.auth.token_response import TokenResponse
from office365.sharepoint.client_context import ClientContext
from tests import test_site_url, test_tenant
cert_settings = {
'client_id': '51d03106-4726-442c-86db-70b32fa7547f',
'thumbprint': "6B36FBFC86FB1C019EB6496494B9195E6D179DDB",
'certificate_path': '{0}/selfsigncert.pem'.format(os.path.dirname(__file__))
}
def acquire_token():
import adal
authority_url = 'https://login.microsoftonline.com/{0}'.format(test_tenant)
auth_ctx = adal.AuthenticationContext(authority_url)
with open(cert_settings['certificate_path'], 'r') as file:
key = file.read()
json_token = auth_ctx.acquire_token_with_client_certificate(
test_site_url,
cert_settings['client_id'],
key,
cert_settings['thumbprint'])
return TokenResponse(**json_token)
ctx = ClientContext(test_site_url).with_access_token(acquire_token)
current_web = ctx.web.get().execute_query()
print("{0}".format(current_web.url))