Skip to content

Commit 5d2676f

Browse files
vvgrem@gmail.comvvgrem@gmail.com
authored andcommitted
Removed adal dependency from ClientContext, removed SP2010 Interface client, OutlookServices namespace migrated into Outlook (MS Graph protocol), auth subsystem refactorings
1 parent 1d7f3d9 commit 5d2676f

File tree

70 files changed

+428
-760
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+428
-760
lines changed

examples/onedrive/export_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def download_files(remote_folder, local_path):
4343
client = GraphClient(get_token)
4444

4545
# load drive properties
46-
target_user_name = settings.get('test_account_name')
46+
target_user_name = settings.get('first_account_name')
4747
drive = client.users[target_user_name].drive
4848
# download files from OneDrive
4949
with tempfile.TemporaryDirectory() as path:

examples/onedrive/upload_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def acquire_token():
2121

2222

2323
client = GraphClient(acquire_token)
24-
user_name = settings.get('test_account_name')
24+
user_name = settings.get('first_account_name')
2525
target_drive = client.users[user_name].drive
2626

2727
local_path = "../../tests/data/SharePoint User Guide.docx"

examples/outlook/send_message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ def get_token():
2626
"ToRecipients": [
2727
{
2828
"EmailAddress": {
29-
"Address": settings.get('test_account_name')
29+
"Address": settings.get('first_account_name')
3030
}
3131
}
3232
]
3333
},
3434
"SaveToSentItems": "false"
3535
}
3636

37-
user_name = settings.get('test_account_name')
37+
user_name = settings.get('first_account_name')
3838
client.users[user_name].send_mail(message_json)
3939
client.execute_query()

examples/sharepoint/connect_with_proxy.py renamed to examples/sharepoint/connect_and_set_proxy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ def set_proxy(request):
99
request.proxies = proxies
1010

1111

12-
ctx = ClientContext.connect_with_credentials(settings['url'],
13-
ClientCredential(settings['client_credentials']['client_id'],
14-
settings['client_credentials']['client_secret']))
12+
ctx = ClientContext(settings['url']).with_credentials(ClientCredential(settings['client_credentials']['client_id'],
13+
settings['client_credentials']['client_secret']))
1514

1615
ctx.pending_request().beforeExecute += set_proxy
1716

examples/sharepoint/connect_with_app.py renamed to examples/sharepoint/connect_with_app_principal.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,5 @@
66
credentials = ClientCredential(settings.get('client_credentials').get('client_id'),
77
settings.get('client_credentials').get('client_secret'))
88
ctx = ClientContext(settings['url']).with_credentials(credentials)
9-
if not ctx.authentication_context.acquire_token_func():
10-
print("Acquire token failed")
11-
12-
13-
target_web = ctx.web
14-
ctx.load(target_web)
15-
ctx.execute_query()
9+
target_web = ctx.web.get().execute_query()
1610
print(target_web.url)

examples/sharepoint/connect_with_azure_app.py

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import adal
3+
4+
from office365.runtime.auth.token_response import TokenResponse
5+
from office365.sharepoint.client_context import ClientContext
6+
from settings import settings
7+
8+
cert_settings = {
9+
'client_id': '51d03106-4726-442c-86db-70b32fa7547f',
10+
'thumbprint': "6B36FBFC86FB1C019EB6496494B9195E6D179DDB",
11+
'certificate_path': '{0}/selfsigncert.pem'.format(os.path.dirname(__file__))
12+
}
13+
14+
15+
def acquire_token():
16+
authority_url = 'https://login.microsoftonline.com/{0}'.format(settings.get('tenant'))
17+
auth_ctx = adal.AuthenticationContext(authority_url)
18+
with open(cert_settings['certificate_path'], 'r') as file:
19+
key = file.read()
20+
json_token = auth_ctx.acquire_token_with_client_certificate(
21+
settings.get('url'),
22+
cert_settings['client_id'],
23+
key,
24+
cert_settings['thumbprint'])
25+
return TokenResponse(**json_token)
26+
27+
28+
ctx = ClientContext(settings['url']).with_access_token(acquire_token)
29+
current_web = ctx.web.get().execute_query()
30+
print("{0}".format(current_web.url))

examples/sharepoint/connect_with_user_creds.py renamed to examples/sharepoint/connect_with_user_credential.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@
77
UserCredential(settings.get('user_credentials').get('username'),
88
settings.get('user_credentials').get('password')))
99

10-
web = ctx.web
11-
ctx.load(web)
12-
ctx.execute_query()
10+
web = ctx.web.get().execute_query()
1311
print(web.properties["Url"])

examples/sharepoint/export_search_crawl_log.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/sharepoint/read_resource_no_model.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
if __name__ == '__main__':
1010
"""Demonstrates how to construct and submit requests without model involved"""
11-
ctx = ClientContext.connect_with_credentials(settings['url'],
12-
UserCredential(settings['user_credentials']['username'],
13-
settings['user_credentials']['password']))
11+
ctx = ClientContext(settings['url']).with_credentials(UserCredential(settings['user_credentials']['username'],
12+
settings['user_credentials']['password']))
1413

1514
request = RequestOptions("{0}/_api/web/".format(settings['url']))
1615
response = ctx.execute_request_direct(request)

0 commit comments

Comments
 (0)