-
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SharePoint API Attachments namespace enhancements
- Loading branch information
Showing
25 changed files
with
717 additions
and
122 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
How to grant and revoke delegated permissions for an app using Microsoft Graph. | ||
Delegated permissions, also called scopes or OAuth2 permissions, allow an app to call an API | ||
on behalf of a signed-in user. | ||
https://learn.microsoft.com/en-us/graph/permissions-grant-via-msgraph?tabs=http&pivots=grant-delegated-permissions | ||
""" | ||
|
||
from office365.graph_client import GraphClient | ||
from tests import ( | ||
test_admin_principal_name, | ||
test_client_id, | ||
test_tenant, | ||
test_user_principal_name, | ||
) | ||
|
||
client = GraphClient.with_token_interactive( | ||
test_tenant, test_client_id, test_admin_principal_name | ||
) | ||
|
||
# Step 1: Get the delegated permissions of the resource service principal | ||
resource = ( | ||
client.service_principals.get_by_name("Microsoft Graph") | ||
.get() | ||
.select(["id", "displayName", "appId", "oauth2PermissionScopes"]) | ||
.execute_query() | ||
) | ||
|
||
|
||
# Step 2: Grant a delegated permission to the client service principal on behalf of a user | ||
app_role = "User.Read.All" | ||
user = client.users.get_by_principal_name(test_user_principal_name) | ||
resource.grant_delegated(test_client_id, user, app_role).execute_query() | ||
|
||
|
||
# Step 3. Confirm and print permission grants | ||
result = ( | ||
client.oauth2_permission_grants.filter("clientId eq '{0}'".format(test_client_id)) | ||
.get() | ||
.execute_query() | ||
) | ||
for grant in result: | ||
print(grant) |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
Revoke delegated permissions granted to a service principal on behalf of a user | ||
https://learn.microsoft.com/en-us/graph/permissions-grant-via-msgraph?tabs=http&pivots=grant-delegated-permissions#step-3-revoke-delegated-permissions-granted-to-a-service-principal-on-behalf-of-a-user-optional | ||
""" | ||
|
||
from office365.graph_client import GraphClient | ||
from tests import ( | ||
test_admin_principal_name, | ||
test_client_id, | ||
test_tenant, | ||
test_user_principal_name, | ||
) | ||
|
||
client = GraphClient.with_token_interactive( | ||
test_tenant, test_client_id, test_admin_principal_name | ||
) | ||
|
||
# Step 1: Get resource service principal | ||
resource = client.service_principals.get_by_name("Microsoft Graph") | ||
user = client.users.get_by_principal_name(test_user_principal_name) | ||
resource.revoke_delegated(test_client_id, user, "User.Read.All").execute_query() |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
""" | ||
Demonstrates how to get a drive by path. | ||
""" | ||
from office365.graph_client import GraphClient | ||
from tests import ( | ||
test_client_id, | ||
test_client_secret, | ||
test_site_url, | ||
test_tenant, | ||
) | ||
|
||
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret) | ||
drive_abs_url = "{0}/Documents".format(test_site_url) | ||
result = client.shares.by_url(drive_abs_url).site.drive.get().execute_query() | ||
print("Drive url: {0}".format(result)) |
File renamed without changes.
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
Oops, something went wrong.