Skip to main content
Solved

Interacting with Sharepoint from CDF Streamlit app

  • November 26, 2024
  • 3 replies
  • 42 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.

View original
Did this topic help you find an answer to your question?

3 replies

Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img

@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.


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings