We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
fireworks

Using Python to connect to SharePoint via App sign-in (Client ID, Secret & Tenant ID)

caltang
17 - Castor
17 - Castor

Hi all, 

 

I've written about this before but no responses. But now, I am writing again with more context and more information provided. My post stems from StackOverflow, where my colleague has posted as well: https://stackoverflow.com/questions/77657489/using-python-to-connect-to-sharepoint-via-app-sign-in-c... 

 

Connecting to SharePoint to Write/Read Files through App Sign in Method (Client ID, Secret & Tenant ID) but wouldn't be able to get authenticated.

I have tried the code below:

 

from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.client_credential import ClientCredential
from office365.runtime.auth.authentication_context import AuthenticationContext
context = ClientContext(SITE_URL).with_credentials(
                      ClientCredential(CLIENT_ID, CLIENT_SECRET))

cert_credentials = {
    "tenant": TENANT_ID,
    "client_id": CLIENT_ID,
    "thumbprint": test_cert_thumbprint,
    "cert_path": "{0}/../selfsignkey.pem".format(os.path.dirname(__file__)),
}
ctx = ClientContext(test_site_url).with_client_certificate(**cert_credentials)
current_web = ctx.web.get().execute_query()
print("{0}".format(current_web.url))

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext

class SharepointService:



        app_principal = {'client_id': CLIENT_ID, 'client_secret': CLIENT_SECRET}

        context_auth = AuthenticationContext(url=site_url)

        token = context_auth.acquire_token_for_app(client_id=app_principal['client_id'], client_secret=app_principal['client_secret'])
        print(token)

        ctx = ClientContext(site_url, context_auth)

        web = ctx.web
        ctx.load(web)
        ctx.execute_query()
        print("Web site title: {0}".format(web.properties['Title']))

 

We ran into this error

 

I would appreciate any and all advice/help on this!!

 

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
3 REPLIES 3
apathetichell
20 - Arcturus

I know close to 0 about Azure workings but here's what I see on that specific error - https://community.auth0.com/t/azure-entra-connection-error-aadsts900023-specified-tenant-identifier-...

 

The two places I'd look would be what's being passed in SITE_URL and test_site_url?

caltang
17 - Castor
17 - Castor

That makes the two of us! I am trying to navigate this with limited IT Access support... just a nightmare. I'll read into what you sent and report back should I find something! Thanks @apathetichell 

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
caltang
17 - Castor
17 - Castor

Hi @apathetichell - I've tried reading your link and going about it, but no luck still. 

 

Hoping someone else can jump in - or even if Alteryx staff / engineers can chime in, that would be great.

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
Labels
Top Solution Authors