Skip to main content
Answer

Interacting with Sharepoint from CDF Streamlit app

  • November 26, 2024
  • 5 replies
  • 102 views

Hi,

I want to let users be able to read/write to a company Sharepoint site via Streamlit in CDF. I am developing locally using Github actions to deploy to CDF. Locally I can acquire tokens using client secret and interactive flow, but both fail in CDF. Client secret using request.post to login.microsoft.com(...) throws with 

JsException: NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://login.microsoftonline.com/xxxxxx-xxx-xxx-xxxxxx/oauth2/v2.0/token'.

Using msal with PublicClientApplication throws with

OSError: [Errno 138] Not supported

Am I trying to do something that I just cant do in the browser in CDF and need to start writing an API for this, or is there a workaround?

Thanks in advance!

Best answer by Anders Hafreager

Hi,

Due to Streamlit is using Pyodide runtime for Python, we have some limitations on these types of use cases. Setting up a proxy server to perform auth could be a workaround, but nothing we officially support as of now. Will keep this post updated with any changes or updates.

5 replies

Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img+8

@Bernt Fredrik Reinhardt can you please share a code snippet of your post request? Please make sure to remove all sensitive infomation before sharing.


Sure. 

 

from msal import PublicClientApplication
import streamlit as st


app_id = "xxxxxxxxx"

app = PublicClientApplication(client_id=app_id)

scopes = ["https://graph.microsoft.com/.default"]

token = app.acquire_token_interactive(scopes)

st.markdown(token)
import streamlit as st
import requests

TENANT_ID = 'xx'
GRAPH_APP_ID = 'xx'
GRAPH_APP_SECRET = 'xx'
SITE_ID = "xx"
GRAPH_URL = f"https://graph.microsoft.com/v1.0/sites/{SITE_ID}"


token_url = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token"
token_data = {
"grant_type": "client_credentials",
"client_id": GRAPH_APP_ID,
"client_secret": GRAPH_APP_SECRET,
"scope": "https://graph.microsoft.com/.default",
}
response = requests.post(token_url,
data=token_data)
import streamlit as st


from azure.identity import ClientSecretCredential

TENANT_ID = 'xx'
GRAPH_APP_ID = 'xx'
GRAPH_APP_SECRET = 'xx'

cred = ClientSecretCredential(TENANT_ID,
GRAPH_APP_ID,
GRAPH_APP_SECRET)

token = cred.get_token("https://graph.microsoft.com/.default")

 


Anders Hafreager
Practitioner

Hi,

Due to Streamlit is using Pyodide runtime for Python, we have some limitations on these types of use cases. Setting up a proxy server to perform auth could be a workaround, but nothing we officially support as of now. Will keep this post updated with any changes or updates.


Forum|alt.badge.img+1

Following. Any updates on this? I have the same problem, our workaround is currently using CDF as a “middleman” for files to be uploaded and read to/from sharepoint, and that is kind of cumbersome.


Anders Hafreager
Practitioner

Hi,

There is no immediate plan on solving this in the product unfortunately. I think the best workaround is to configure a Cognite function to perform the network call and have the app communicate to the Cognite function.