-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
281 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +0,0 @@ | ||
import os | ||
|
||
import msal | ||
|
||
from tests import load_settings | ||
|
||
settings = load_settings() | ||
|
||
# aliases | ||
sample_client_id = settings.get('client_credentials', 'client_id') | ||
sample_client_secret = settings.get('client_credentials', 'client_secret') | ||
sample_user_principal_name = settings.get('users', 'test_user1') | ||
sample_user_principal_name_alt = settings.get('users', 'test_user2') | ||
sample_tenant_prefix = settings.get('default', 'tenant_prefix') | ||
sample_tenant_name = settings.get('default', 'tenant') | ||
sample_thumbprint = settings.get('certificate_credentials', 'thumbprint') | ||
sample_cert_path = '{0}/selfsigncert.pem'.format(os.path.dirname(__file__)) | ||
sample_site_url = settings.get('default', 'site_url') | ||
sample_username = settings.get('user_credentials', "username") | ||
sample_password = settings.get('user_credentials', "password") | ||
|
||
|
||
def acquire_token_by_username_password(): | ||
authority_url = 'https://login.microsoftonline.com/{0}'.format(sample_tenant_name) | ||
app = msal.PublicClientApplication( | ||
authority=authority_url, | ||
client_id=sample_client_id | ||
) | ||
return app.acquire_token_by_username_password(username=settings.get('user_credentials', "username"), | ||
password=settings.get('user_credentials', "password"), | ||
scopes=["https://graph.microsoft.com/.default"]) | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 23 additions & 6 deletions
29
examples/sharepoint/connect_with_client_certificate_private_key.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,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 examples import sample_tenant_name, sample_client_id, sample_thumbprint, sample_site_url | ||
from office365.sharepoint.client_context import ClientContext | ||
|
||
from tests import test_client_id, test_cert_thumbprint, test_site_url, test_tenant_name | ||
|
||
cert_path = '{0}/selfsigncert.pem'.format(os.path.dirname(__file__)) | ||
with open(cert_path, 'r') as f: | ||
private_key = open(cert_path).read() | ||
|
||
cert_credentials = { | ||
'tenant': sample_tenant_name, | ||
'client_id': sample_client_id, | ||
'thumbprint': sample_thumbprint, | ||
'tenant': test_tenant_name, | ||
'client_id': test_client_id, | ||
'thumbprint': test_cert_thumbprint, | ||
'private_key': private_key | ||
} | ||
ctx = ClientContext(sample_site_url).with_client_certificate(**cert_credentials) | ||
ctx = ClientContext(test_site_url).with_client_certificate(**cert_credentials) | ||
current_web = ctx.web.get().execute_query() | ||
print("{0}".format(current_web.url)) |
15 changes: 9 additions & 6 deletions
15
examples/sharepoint/connect_with_client_certificate_scopes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
""" | ||
""" | ||
import os | ||
|
||
from examples import sample_client_id, sample_thumbprint, sample_tenant_name, sample_site_url | ||
from office365.sharepoint.client_context import ClientContext | ||
from tests import test_tenant_name, test_client_id, test_cert_thumbprint, test_site_url | ||
|
||
cert_credentials = { | ||
'tenant': sample_tenant_name, | ||
'client_id': sample_client_id, | ||
'thumbprint': sample_thumbprint, | ||
'tenant': test_tenant_name, | ||
'client_id': test_client_id, | ||
'thumbprint': test_cert_thumbprint, | ||
'cert_path': '{0}/selfsigncert.pem'.format(os.path.dirname(__file__)), | ||
'scopes': ['{0}/.default'.format(sample_site_url)] | ||
'scopes': ['{0}/.default'.format(test_site_url)] | ||
} | ||
|
||
ctx = ClientContext(sample_site_url).with_client_certificate(**cert_credentials) | ||
ctx = ClientContext(test_site_url).with_client_certificate(**cert_credentials) | ||
current_web = ctx.web.get().execute_query() | ||
print("{0}".format(current_web.url)) |
Oops, something went wrong.