Skip to content

Commit 6d7f9d4

Browse files
committed
GraphClient client refactorings in terms of authentication
1 parent 53eddff commit 6d7f9d4

File tree

158 files changed

+670
-379
lines changed

Some content is hidden

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

158 files changed

+670
-379
lines changed

examples/auth/interactive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from office365.graph_client import GraphClient
1414
from tests import test_client_id, test_tenant
1515

16-
client = GraphClient.with_token_interactive(test_tenant, test_client_id)
16+
client = GraphClient(tenant=test_tenant).with_token_interactive(test_client_id)
1717
me = client.me.get().execute_query()
1818
print("Welcome, {0}!".format(me.given_name))
1919
site = client.sites.root.get().execute_query()

examples/auth/register_sharepoint_apponly.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
from office365.graph_client import GraphClient
1818
from tests import test_client_id, test_password, test_tenant, test_username
1919

20-
admin_client = GraphClient.with_username_and_password(
21-
test_tenant, test_client_id, test_username, test_password
20+
admin_client = GraphClient(tenant=test_tenant).with_username_and_password(
21+
test_client_id, test_username, test_password
2222
)

examples/auth/with_client_secret.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Acquires a token by using application secret
33
44
The following options are supported:
5-
- utilize built in GraphClient.with_client_secret(tenant, client_id, client_secret, scopes, token_cache) method
5+
- utilize built in GraphClient(tenant=tenant).with_client_secret(client_id, client_secret) method
66
- or provide a custom callback function to GraphClient constructor as demonstrated below
77
88
https://learn.microsoft.com/en-us/entra/identity-platform/msal-authentication-flows#client-credentials

examples/auth/with_user_creds.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient.with_username_and_password(
11-
test_tenant, test_client_id, test_username, test_password
10+
client = GraphClient(tenant=test_tenant).with_username_and_password(
11+
test_client_id, test_username, test_password
1212
)
1313
me = client.me.get().execute_query()
14-
print(me.user_principal_name)
14+
print(me)

examples/communications/create_call.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from office365.graph_client import GraphClient
66
from tests import test_client_id, test_client_secret, test_tenant
77

8-
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
8+
client = GraphClient(tenant=test_tenant).with_client_secret(
9+
test_client_id, test_client_secret
10+
)
911
call = client.communications.calls.create(
1012
"https://mediadev8.com/teamsapp/api/calling"
1113
).execute_query()

examples/directory/applications/add_cert.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
cert_path = "../../selfsigncert.pem"
1414

15-
client = GraphClient.with_username_and_password(
16-
test_tenant, test_client_id, test_username, test_password
15+
client = GraphClient(tenant=test_tenant).with_username_and_password(
16+
test_client_id, test_username, test_password
1717
)
1818
target_app = client.applications.get_by_app_id(test_client_id)
1919
with open(cert_path, "rb") as f:

examples/directory/applications/app_password.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
test_username,
1313
)
1414

15-
client = GraphClient.with_username_and_password(
16-
test_tenant, test_client_id, test_username, test_password
15+
client = GraphClient(tenant=test_tenant).with_username_and_password(
16+
test_client_id, test_username, test_password
1717
)
1818
target_app = client.applications.get_by_app_id(test_client_credentials.clientId)
1919
result = target_app.add_password("Password friendly name").execute_query()

examples/directory/applications/get_by_app_id.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from office365.graph_client import GraphClient
1111
from tests import test_client_id, test_client_secret, test_tenant
1212

13-
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
13+
client = GraphClient(tenant=test_tenant).with_client_secret(
14+
test_client_id, test_client_secret
15+
)
1416
app = client.applications.get_by_app_id(test_client_id).get().execute_query()
1517
print(app)

examples/directory/applications/grant_application_perms.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
test_tenant,
2323
)
2424

25-
client = GraphClient.with_token_interactive(
26-
test_tenant, test_client_id, test_admin_principal_name
25+
client = GraphClient(tenant=test_tenant).with_token_interactive(
26+
test_client_id, test_admin_principal_name
2727
)
28-
# client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
2928

3029
# Step 1: Get the resource service principal
3130
resource = client.service_principals.get_by_name("Microsoft Graph")

examples/directory/applications/grant_delegated_perms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
test_user_principal_name,
1616
)
1717

18-
client = GraphClient.with_token_interactive(
19-
test_tenant, test_client_id, test_admin_principal_name
18+
client = GraphClient(tenant=test_tenant).with_token_interactive(
19+
test_client_id, test_admin_principal_name
2020
)
2121

2222

examples/directory/applications/has_application_perms.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
test_tenant,
1515
)
1616

17-
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
17+
client = GraphClient(tenant=test_tenant).with_client_secret(
18+
test_client_id, test_client_secret
19+
)
1820

1921

2022
resource = client.service_principals.get_by_name("Microsoft Graph")

examples/directory/applications/has_delegated_perms.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
test_tenant,
1313
)
1414

15-
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
15+
client = GraphClient(tenant=test_tenant).with_client_secret(
16+
test_client_id, test_client_secret
17+
)
1618

1719
resource = client.service_principals.get_by_name("Microsoft Graph")
1820
scope = "DeviceLocalCredential.Read.All"

examples/directory/applications/list_application_perms.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
test_tenant,
1515
)
1616

17-
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
17+
client = GraphClient(tenant=test_tenant).with_client_secret(
18+
test_client_id, test_client_secret
19+
)
1820

1921

2022
resource = client.service_principals.get_by_name("Microsoft Graph")

examples/directory/applications/list_delegated_perms.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
test_tenant,
1515
)
1616

17-
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
17+
client = GraphClient(tenant=test_tenant).with_client_secret(
18+
test_client_id, test_client_secret
19+
)
1820

1921

2022
resource = client.service_principals.get_by_name("Microsoft Graph")

examples/directory/applications/revoke_application_perms.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
test_username,
1414
)
1515

16-
# client = GraphClient.with_token_interactive(
17-
# test_tenant, test_client_id, test_admin_principal_name
18-
# )
19-
20-
client = GraphClient.with_username_and_password(
21-
test_tenant, test_client_id, test_username, test_password
16+
client = GraphClient(tenant=test_tenant).with_username_and_password(
17+
test_client_id, test_username, test_password
2218
)
2319

2420

examples/directory/applications/revoke_delegated_perms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
test_user_principal_name,
1313
)
1414

15-
client = GraphClient.with_token_interactive(
16-
test_tenant, test_client_id, test_admin_principal_name
15+
client = GraphClient(tenant=test_tenant).with_token_interactive(
16+
test_client_id, test_admin_principal_name
1717
)
1818

1919
# Step 1: Get resource service principal

examples/directory/groups/create_m365.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
)
1818

1919
grp_name = create_unique_name("Group")
20-
client = GraphClient.with_username_and_password(
21-
test_tenant, test_client_id, test_username, test_password
20+
client = GraphClient(tenant=test_tenant).with_username_and_password(
21+
test_client_id, test_username, test_password
2222
)
2323
group = client.groups.create_m365(grp_name).execute_query()
2424

examples/directory/groups/create_with_team.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def print_failure(retry_number, ex):
2121
print(f"{retry_number}: Team creation still in progress, waiting...")
2222

2323

24-
client = GraphClient.with_username_and_password(
25-
test_tenant, test_client_id, test_username, test_password
24+
client = GraphClient(tenant=test_tenant).with_username_and_password(
25+
test_client_id, test_username, test_password
2626
)
2727
group_name = create_unique_name("Flight")
2828
group = client.groups.create_with_team(group_name).execute_query_retry(

examples/directory/groups/delete_batch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient.with_username_and_password(
11-
test_tenant, test_client_id, test_username, test_password
10+
client = GraphClient(tenant=test_tenant).with_username_and_password(
11+
test_client_id, test_username, test_password
1212
)
1313

1414
result = client.groups.get_all().execute_query()

examples/directory/groups/delete_groups.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from office365.graph_client import GraphClient
1313
from tests import test_client_id, test_password, test_tenant, test_username
1414

15-
client = GraphClient.with_username_and_password(
16-
test_tenant, test_client_id, test_username, test_password
15+
client = GraphClient(tenant=test_tenant).with_username_and_password(
16+
test_client_id, test_username, test_password
1717
)
1818
groups = client.groups.get().top(10).execute_query()
1919
deletedCount = 0

examples/directory/groups/list.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_client_secret, test_tenant
99

10-
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
10+
client = GraphClient(tenant=test_tenant).with_client_secret(
11+
test_client_id, test_client_secret
12+
)
1113
groups = client.groups.get().top(100).execute_query()
1214
for grp in groups:
1315
print(grp)

examples/directory/identity/list_provider.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_client_secret, test_tenant
99

10-
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
10+
client = GraphClient(tenant=test_tenant).with_client_secret(
11+
test_client_id, test_client_secret
12+
)
1113
providers = client.identity.identity_providers.get().execute_query()
1214
for idp in providers:
1315
print(idp.display_name)

examples/directory/policies/get_auth_settings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from office365.graph_client import GraphClient
1111
from tests import test_admin_principal_name, test_client_id, test_tenant
1212

13-
client = GraphClient.with_token_interactive(
14-
test_tenant, test_client_id, test_admin_principal_name
13+
client = GraphClient(tenant=test_tenant).with_token_interactive(
14+
test_client_id, test_admin_principal_name
1515
)
1616

1717

examples/directory/roles/for_user.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient.with_username_and_password(
11-
test_tenant, test_client_id, test_username, test_password
10+
client = GraphClient(tenant=test_tenant).with_username_and_password(
11+
test_client_id, test_username, test_password
1212
)
1313
result = client.me.member_of.get().execute_query()
1414
role_template_ids = [

examples/directory/roles/list.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_client_secret, test_tenant
99

10-
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
10+
client = GraphClient(tenant=test_tenant).with_client_secret(
11+
test_client_id, test_client_secret
12+
)
1113
roles = client.directory_roles.get().execute_query()
1214
for role in roles:
1315
print(role)

examples/directory/users/assign_manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
test_username,
1414
)
1515

16-
client = GraphClient.with_username_and_password(
17-
test_tenant, test_client_id, test_username, test_password
16+
client = GraphClient(tenant=test_tenant).with_username_and_password(
17+
test_client_id, test_username, test_password
1818
)
1919
manager = client.users.get_by_principal_name(test_user_principal_name)
2020
client.me.assign_manager(manager).get().execute_query()

examples/directory/users/export_personal_data.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient.with_username_and_password(
11-
test_tenant, test_client_id, test_username, test_password
10+
client = GraphClient(tenant=test_tenant).with_username_and_password(
11+
test_client_id, test_username, test_password
1212
)
1313
result = client.me.export_personal_data("storageLocation-value").execute_query()

examples/directory/users/get_licenses.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient.with_username_and_password(
11-
test_tenant, test_client_id, test_username, test_password
10+
client = GraphClient(tenant=test_tenant).with_username_and_password(
11+
test_client_id, test_username, test_password
1212
)
1313
result = client.me.license_details.get().execute_query()
1414
for details in result:

examples/directory/users/get_my_activities.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from office365.graph_client import GraphClient
77
from tests import test_client_id, test_password, test_tenant, test_username
88

9-
client = GraphClient.with_username_and_password(
10-
test_tenant, test_client_id, test_username, test_password
9+
client = GraphClient(tenant=test_tenant).with_username_and_password(
10+
test_client_id, test_username, test_password
1111
)
1212
activities = client.me.activities.get().top(5).execute_query()
1313
for activity in activities:

examples/directory/users/import.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def generate_user_profile():
2828
return UserProfile(**user_json)
2929

3030

31-
client = GraphClient.with_username_and_password(
32-
test_tenant, test_client_id, test_username, test_password
31+
client = GraphClient(tenant=test_tenant).with_username_and_password(
32+
test_client_id, test_username, test_password
3333
)
3434

3535
for idx in range(0, 1):

examples/directory/users/list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient.with_username_and_password(
11-
test_tenant, test_client_id, test_username, test_password
10+
client = GraphClient(tenant=test_tenant).with_username_and_password(
11+
test_client_id, test_username, test_password
1212
)
1313
users = client.users.get().top(10).execute_query()
1414
for u in users:

examples/directory/users/list_app_role_assignments.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from office365.graph_client import GraphClient
66
from tests import test_client_id, test_password, test_tenant, test_username
77

8-
client = GraphClient.with_username_and_password(
9-
test_tenant, test_client_id, test_username, test_password
8+
client = GraphClient(tenant=test_tenant).with_username_and_password(
9+
test_client_id, test_username, test_password
1010
)
1111

1212
result = client.me.app_role_assignments.get().execute_query()

examples/directory/users/update.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient.with_username_and_password(
11-
test_tenant, test_client_id, test_username, test_password
10+
client = GraphClient(tenant=test_tenant).with_username_and_password(
11+
test_client_id, test_username, test_password
1212
)
1313
users = (
1414
client.users.get()

examples/directory/users/update_batch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from office365.graph_client import GraphClient
88
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient.with_username_and_password(
11-
test_tenant, test_client_id, test_username, test_password
10+
client = GraphClient(tenant=test_tenant).with_username_and_password(
11+
test_client_id, test_username, test_password
1212
)
1313
users = (
1414
client.users.get()

examples/informationprotection/create_mail_assessment.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from office365.graph_client import GraphClient
77
from tests import test_client_id, test_password, test_tenant, test_username
88

9-
client = GraphClient.with_username_and_password(
10-
test_tenant, test_client_id, test_username, test_password
9+
client = GraphClient(tenant=test_tenant).with_username_and_password(
10+
test_client_id, test_username, test_password
1111
)
1212
messages = client.me.messages.get().filter("isDraft eq false").top(1).execute_query()
1313
result = client.information_protection.create_mail_assessment(

examples/insights/list_shared.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from office365.graph_client import GraphClient
1111
from tests import test_client_id, test_password, test_tenant, test_username
1212

13-
client = GraphClient.with_username_and_password(
14-
test_tenant, test_client_id, test_username, test_password
13+
client = GraphClient(tenant=test_tenant).with_username_and_password(
14+
test_client_id, test_username, test_password
1515
)
1616
result = client.me.insights.shared.get().execute_query()
1717
for item in result:

0 commit comments

Comments
 (0)