Skip to content

Commit 03330dc

Browse files
committed
directory namespace improvements & refactorings
1 parent 70e6fe8 commit 03330dc

Some content is hidden

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

41 files changed

+463
-130
lines changed

examples/directory/applications/get_delegated_perms.py

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

examples/directory/applications/grant_application_perms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# Step 2: Grant an app role to a client app
3232
app = client.applications.get_by_app_id(test_client_id)
33-
resource.grant_application(app, "MailboxSettings.Read").execute_query()
33+
resource.grant_application_permissions(app, "MailboxSettings.Read").execute_query()
3434

3535

3636
# Step 3. Print app role assignments

examples/directory/applications/grant_delegated_perms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
# app_role = "User.Read.All"
2525
app_role = "DeviceLocalCredential.Read.All"
2626
user = client.users.get_by_principal_name(test_user_principal_name)
27-
resource.grant_delegated(test_client_id, user, app_role).execute_query()
27+
resource.grant_delegated_permissions(test_client_id, user, app_role).execute_query()

examples/directory/applications/has_delegated_perms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
user = client.users.get_by_principal_name(test_admin_principal_name)
2525
client_app = client.applications.get_by_app_id(test_client_id)
2626
# result = resource.get_delegated(client_app, user, app_role).execute_query()
27-
result = resource.get_delegated(test_client_id, user, app_role).execute_query()
27+
result = resource.get_delegated_permissions(test_client_id, user, app_role).execute_query()
2828
if len(result) == 0:
2929
print("Delegated permission '{0}' is not set".format(app_role))
3030
else:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
How to grant and revoke delegated permissions for an app using Microsoft Graph.
3+
Delegated permissions, also called scopes or OAuth2 permissions, allow an app to call an API
4+
on behalf of a signed-in user.
5+
6+
7+
https://learn.microsoft.com/en-us/graph/permissions-grant-via-msgraph?tabs=http&pivots=grant-delegated-permissions
8+
"""
9+
10+
from office365.graph_client import GraphClient
11+
from tests import (
12+
test_client_id,
13+
test_tenant,
14+
test_client_secret,
15+
)
16+
17+
# client = GraphClient.with_token_interactive(
18+
# test_tenant, test_client_id, test_admin_principal_name
19+
# )
20+
21+
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
22+
23+
24+
resource = (
25+
client.service_principals.get_by_name("Microsoft Graph")
26+
)
27+
28+
result = resource.get_application_permissions(test_client_id).execute_query()
29+
for app_role in result.value:
30+
print(app_role)
31+
32+
33+
34+

examples/directory/applications/list_delegated_perms.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99

1010
from office365.graph_client import GraphClient
1111
from tests import (
12-
test_admin_principal_name,
1312
test_client_id,
1413
test_tenant,
15-
test_user_principal_name,
14+
test_client_secret,
1615
)
1716

18-
client = GraphClient.with_token_interactive(
19-
test_tenant, test_client_id, test_admin_principal_name
20-
)
17+
#client = GraphClient.with_token_interactive(
18+
# test_tenant, test_client_id, test_admin_principal_name
19+
#)
20+
21+
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
2122

2223

23-
resource = client.service_principals.get_by_name("Microsoft Graph")
24-
user = client.users.get_by_principal_name(test_user_principal_name)
25-
result = resource.get_delegated(test_client_id, user).execute_query()
24+
resource = client.service_principals.get_by_name("Microsoft Graph").get().execute_query()
25+
result = resource.get_delegated_permissions(test_client_id, only_admin_consent=True).execute_query()
2626

2727
for grant in result:
28-
print(grant)
28+
print(grant.scope)

examples/directory/applications/revoke_application_perms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424

2525
# Get resource
2626
resource = client.service_principals.get_by_name("Microsoft Graph")
27-
resource.revoke_application(test_client_id, "MailboxSettings.Read").execute_query()
27+
resource.revoke_application_permissions(test_client_id, "MailboxSettings.Read").execute_query()

examples/directory/applications/revoke_delegated_perms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
# Step 1: Get resource service principal
2020
resource = client.service_principals.get_by_name("Microsoft Graph")
2121
user = client.users.get_by_principal_name(test_user_principal_name)
22-
resource.revoke_delegated(test_client_id, user, "User.Read.All").execute_query()
22+
resource.revoke_delegated_permissions(test_client_id, user, "User.Read.All").execute_query()

examples/security/run_hunting_query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
1616
query = """
17-
DeviceProcessEvents | where InitiatingProcessFileName =~ \"powershell.exe\"
18-
| project Timestamp, FileName, InitiatingProcessFileName
19-
| order by Timestamp desc | limit 2"""
17+
DeviceProcessEvents | where InitiatingProcessFileName =~ \"powershell.exe\" | project Timestamp, FileName, \
18+
InitiatingProcessFileName | order by Timestamp desc | limit 2"""
2019
result = client.security.run_hunting_query(query).execute_query()
2120
print(result.value)

examples/sharepoint/__init__.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,3 @@
1-
from office365.sharepoint.fields.creation_information import FieldCreationInformation
2-
from office365.sharepoint.fields.type import FieldType
3-
from office365.sharepoint.lists.creation_information import ListCreationInformation
4-
from office365.sharepoint.lists.list import List
5-
from office365.sharepoint.lists.template_type import ListTemplateType
6-
from office365.sharepoint.webs.web import Web
7-
from tests import create_unique_name
81

92

10-
def upload_sample_file(context, path):
11-
"""
12-
:type context: office365.sharepoint.client_context.ClientContext
13-
:type path: str
14-
"""
15-
folder = context.web.default_document_library().root_folder
16-
with open(path, "rb") as f:
17-
file = folder.files.upload(f).execute_query()
18-
return file
193

20-
21-
def create_sample_tasks_list(web):
22-
# type: (Web) -> List
23-
list_title = "Company Tasks"
24-
25-
list_title = create_unique_name("Tasks N")
26-
list_create_info = ListCreationInformation(
27-
list_title, None, ListTemplateType.TasksWithTimelineAndHierarchy
28-
)
29-
30-
return_type = web.lists.add(list_create_info).execute_query()
31-
field_info = FieldCreationInformation("Manager", FieldType.User)
32-
return_type.fields.add(field_info).execute_query()
33-
return return_type
34-
35-
36-
def configure():
37-
pass

0 commit comments

Comments
 (0)