Skip to content

Instantly share code, notes, and snippets.

@nuriozbey
Last active September 6, 2022 10:12
Show Gist options
  • Save nuriozbey/67610bce732e72cde64052d6465d2f1b to your computer and use it in GitHub Desktop.
Save nuriozbey/67610bce732e72cde64052d6465d2f1b to your computer and use it in GitHub Desktop.
Connect Sharepoint with Client Id ad Client Secret
import os
import json
from office365.runtime.auth.client_credential import ClientCredential
from office365.sharepoint.client_context import ClientContext
def connect_sharepoint(cwd= os.getcwd()): # provide json contained folder
with open(os.path.join(cwd,"sharepoint_credentials.json")) as file:
credentials = json.load(file)
sp_site = 'https://<org>.sharepoint.com/sites/<my_site>/' # you should enter correct
client_credentials = ClientCredential(credentials['client_id'], credentials['client_secret'])
ctx = ClientContext(sp_site).with_credentials(client_credentials)
return ctx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment