|
1 | 1 | """ |
2 | | -Determines whether the delegated permissions is defined by the Microsoft Graph service principal in the tenant. |
| 2 | +Determines whether the delegated permissions is granted by the Microsoft Graph service principal in the tenant. |
3 | 3 |
|
4 | 4 | https://learn.microsoft.com/en-us/graph/permissions-grant-via-msgraph?tabs=http&pivots=grant-delegated-permissions |
5 | 5 | """ |
|
8 | 8 | from tests import ( |
9 | 9 | test_admin_principal_name, |
10 | 10 | test_client_id, |
| 11 | + test_client_secret, |
11 | 12 | test_tenant, |
12 | 13 | ) |
13 | 14 |
|
14 | | -# client = GraphClient.with_username_and_password( |
15 | | -# test_tenant, test_client_id, test_username, test_password |
16 | | -# ) |
17 | | -client = GraphClient.with_token_interactive( |
18 | | - test_tenant, test_client_id, test_admin_principal_name |
19 | | -) |
| 15 | +client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret) |
20 | 16 |
|
21 | 17 | resource = client.service_principals.get_by_name("Microsoft Graph") |
22 | | -# app_role = "User.Read.All" |
23 | | -app_role = "DeviceLocalCredential.Read.All" |
| 18 | +scope = "DeviceLocalCredential.Read.All" |
24 | 19 | user = client.users.get_by_principal_name(test_admin_principal_name) |
25 | 20 | client_app = client.applications.get_by_app_id(test_client_id) |
26 | | -# result = resource.get_delegated(client_app, user, app_role).execute_query() |
27 | | -result = resource.get_delegated_permissions( |
28 | | - test_client_id, user, app_role |
29 | | -).execute_query() |
30 | | -if len(result) == 0: |
31 | | - print("Delegated permission '{0}' is not set".format(app_role)) |
| 21 | +# result = resource.get_delegated_permissions(test_client_id, user).execute_query() |
| 22 | +result = resource.get_delegated_permissions(test_client_id).execute_query() |
| 23 | +if len([cur_scope for cur_scope in result.value if cur_scope == scope]) == 0: |
| 24 | + print("Delegated permission '{0}' is not granted".format(scope)) |
32 | 25 | else: |
33 | 26 | print(result.value) |
0 commit comments