Skip to content

Commit

Permalink
GraphClient client refactorings in terms of authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Jan 14, 2025
1 parent 53eddff commit 6d7f9d4
Show file tree
Hide file tree
Showing 158 changed files with 670 additions and 379 deletions.
2 changes: 1 addition & 1 deletion examples/auth/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_tenant

client = GraphClient.with_token_interactive(test_tenant, test_client_id)
client = GraphClient(tenant=test_tenant).with_token_interactive(test_client_id)
me = client.me.get().execute_query()
print("Welcome, {0}!".format(me.given_name))
site = client.sites.root.get().execute_query()
Expand Down
4 changes: 2 additions & 2 deletions examples/auth/register_sharepoint_apponly.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

admin_client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
admin_client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
2 changes: 1 addition & 1 deletion examples/auth/with_client_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Acquires a token by using application secret
The following options are supported:
- utilize built in GraphClient.with_client_secret(tenant, client_id, client_secret, scopes, token_cache) method
- utilize built in GraphClient(tenant=tenant).with_client_secret(client_id, client_secret) method
- or provide a custom callback function to GraphClient constructor as demonstrated below
https://learn.microsoft.com/en-us/entra/identity-platform/msal-authentication-flows#client-credentials
Expand Down
6 changes: 3 additions & 3 deletions examples/auth/with_user_creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
me = client.me.get().execute_query()
print(me.user_principal_name)
print(me)
4 changes: 3 additions & 1 deletion examples/communications/create_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)
call = client.communications.calls.create(
"https://mediadev8.com/teamsapp/api/calling"
).execute_query()
4 changes: 2 additions & 2 deletions examples/directory/applications/add_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

cert_path = "../../selfsigncert.pem"

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
target_app = client.applications.get_by_app_id(test_client_id)
with open(cert_path, "rb") as f:
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/applications/app_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
test_username,
)

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
target_app = client.applications.get_by_app_id(test_client_credentials.clientId)
result = target_app.add_password("Password friendly name").execute_query()
Expand Down
4 changes: 3 additions & 1 deletion examples/directory/applications/get_by_app_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)
app = client.applications.get_by_app_id(test_client_id).get().execute_query()
print(app)
5 changes: 2 additions & 3 deletions examples/directory/applications/grant_application_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
test_tenant,
)

client = GraphClient.with_token_interactive(
test_tenant, test_client_id, test_admin_principal_name
client = GraphClient(tenant=test_tenant).with_token_interactive(
test_client_id, test_admin_principal_name
)
# client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)

# Step 1: Get the resource service principal
resource = client.service_principals.get_by_name("Microsoft Graph")
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/applications/grant_delegated_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
test_user_principal_name,
)

client = GraphClient.with_token_interactive(
test_tenant, test_client_id, test_admin_principal_name
client = GraphClient(tenant=test_tenant).with_token_interactive(
test_client_id, test_admin_principal_name
)


Expand Down
4 changes: 3 additions & 1 deletion examples/directory/applications/has_application_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
test_tenant,
)

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)


resource = client.service_principals.get_by_name("Microsoft Graph")
Expand Down
4 changes: 3 additions & 1 deletion examples/directory/applications/has_delegated_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
test_tenant,
)

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)

resource = client.service_principals.get_by_name("Microsoft Graph")
scope = "DeviceLocalCredential.Read.All"
Expand Down
4 changes: 3 additions & 1 deletion examples/directory/applications/list_application_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
test_tenant,
)

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)


resource = client.service_principals.get_by_name("Microsoft Graph")
Expand Down
4 changes: 3 additions & 1 deletion examples/directory/applications/list_delegated_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
test_tenant,
)

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)


resource = client.service_principals.get_by_name("Microsoft Graph")
Expand Down
8 changes: 2 additions & 6 deletions examples/directory/applications/revoke_application_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
test_username,
)

# client = GraphClient.with_token_interactive(
# test_tenant, test_client_id, test_admin_principal_name
# )

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)


Expand Down
4 changes: 2 additions & 2 deletions examples/directory/applications/revoke_delegated_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
test_user_principal_name,
)

client = GraphClient.with_token_interactive(
test_tenant, test_client_id, test_admin_principal_name
client = GraphClient(tenant=test_tenant).with_token_interactive(
test_client_id, test_admin_principal_name
)

# Step 1: Get resource service principal
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/groups/create_m365.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
)

grp_name = create_unique_name("Group")
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
group = client.groups.create_m365(grp_name).execute_query()

Expand Down
4 changes: 2 additions & 2 deletions examples/directory/groups/create_with_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def print_failure(retry_number, ex):
print(f"{retry_number}: Team creation still in progress, waiting...")


client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
group_name = create_unique_name("Flight")
group = client.groups.create_with_team(group_name).execute_query_retry(
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/groups/delete_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)

result = client.groups.get_all().execute_query()
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/groups/delete_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
groups = client.groups.get().top(10).execute_query()
deletedCount = 0
Expand Down
4 changes: 3 additions & 1 deletion examples/directory/groups/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)
groups = client.groups.get().top(100).execute_query()
for grp in groups:
print(grp)
4 changes: 3 additions & 1 deletion examples/directory/identity/list_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)
providers = client.identity.identity_providers.get().execute_query()
for idp in providers:
print(idp.display_name)
4 changes: 2 additions & 2 deletions examples/directory/policies/get_auth_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from office365.graph_client import GraphClient
from tests import test_admin_principal_name, test_client_id, test_tenant

client = GraphClient.with_token_interactive(
test_tenant, test_client_id, test_admin_principal_name
client = GraphClient(tenant=test_tenant).with_token_interactive(
test_client_id, test_admin_principal_name
)


Expand Down
4 changes: 2 additions & 2 deletions examples/directory/roles/for_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
result = client.me.member_of.get().execute_query()
role_template_ids = [
Expand Down
4 changes: 3 additions & 1 deletion examples/directory/roles/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
client = GraphClient(tenant=test_tenant).with_client_secret(
test_client_id, test_client_secret
)
roles = client.directory_roles.get().execute_query()
for role in roles:
print(role)
4 changes: 2 additions & 2 deletions examples/directory/users/assign_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
test_username,
)

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
manager = client.users.get_by_principal_name(test_user_principal_name)
client.me.assign_manager(manager).get().execute_query()
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/users/export_personal_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
result = client.me.export_personal_data("storageLocation-value").execute_query()
4 changes: 2 additions & 2 deletions examples/directory/users/get_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
result = client.me.license_details.get().execute_query()
for details in result:
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/users/get_my_activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
activities = client.me.activities.get().top(5).execute_query()
for activity in activities:
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/users/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def generate_user_profile():
return UserProfile(**user_json)


client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)

for idx in range(0, 1):
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/users/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
users = client.users.get().top(10).execute_query()
for u in users:
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/users/list_app_role_assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)

result = client.me.app_role_assignments.get().execute_query()
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/users/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
users = (
client.users.get()
Expand Down
4 changes: 2 additions & 2 deletions examples/directory/users/update_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
users = (
client.users.get()
Expand Down
4 changes: 2 additions & 2 deletions examples/informationprotection/create_mail_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
messages = client.me.messages.get().filter("isDraft eq false").top(1).execute_query()
result = client.information_protection.create_mail_assessment(
Expand Down
4 changes: 2 additions & 2 deletions examples/insights/list_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from office365.graph_client import GraphClient
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
client = GraphClient(tenant=test_tenant).with_username_and_password(
test_client_id, test_username, test_password
)
result = client.me.insights.shared.get().execute_query()
for item in result:
Expand Down
Loading

0 comments on commit 6d7f9d4

Please sign in to comment.