Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23305

MSAL No response after I depoly my streamlit login page to Azure APP service

$
0
0

I wrote a login page using streamlit and MSAL, because I want to authenticate through microsoft Entra ID. Everything work fine when I ran the script on my local machine. I was able to get redirect to a login page when I click "login" button.After I depolyed my script to Azure App service through GitHub, the login page shows up normally, but I was unable to get any redirect or any interaction at all when i click the login button.Below is my code, only main.py needs to run and login_page.py is where I put all the authentication functions:main.py:

import streamlit as stfrom login_page import acquire_and_use_tokendef main():    add_selectbox = st.sidebar.container(border=True)    st.write(st.session_state)    if "access_token" not in st.session_state or st.session_state.access_token == None:        st.title("Azure Entra ID Login Pagee")        st.title("Azure Entra ID Login Page")        st.write("Authenticate to access protected content")        add_selectbox = st.sidebar.container(border=True)        login_button_clicked = add_selectbox.button("Azure Login", type="primary")        if login_button_clicked:            st.session_state.access_token = None            access_token = acquire_and_use_token()            st.session_state.access_token = access_token            st.rerun()    else:        st.title("AI Chatbot Page")        st.write("content placeholder")        st.write(st.session_state)        if st.button("Sign out"):            st.session_state.access_token = None            st.session_state.clear()            st.rerun()if __name__ == "__main__":    main()

login_page.py:

import streamlit as stfrom msal import PublicClientApplicationdef acquire_and_use_token():    app = PublicClientApplication("<CLIENT ID>",    authority="https://login.microsoftonline.com/<Tenant ID>",    )    accounts = app.get_accounts()    if accounts:        result = app.acquire_token_silent(["User.Read"], account=accounts[0])    else:        result = app.acquire_token_interactive(scopes=["User.Read"], prompt="select_account")    if "access_token" in result:        st.write("Protected content available")        return result["access_token"]    else:        st.error("Token acquisition failed")        st.error(result.get("error_description", "No further details"))

After I depoly the script to App service, the page display as expected, but when i click login, i see no interaction and response at all. It works perfectly on local machine.If someone can help me troubleshoot the problem?the error message from server: 2024-05-19T00:31:37.893621387Z: [ERROR] Found no browser in current environment. If this program is being run inside a container which either (1) has access to host network (i.e. started by docker run --net=host -it ...), or (2) published port 35413 to host network (i.e. started by docker run -p 127.0.0.1:35413:35413 -it ...), you can use browser on host to visit the following link. Otherwise, this auth attempt would either timeout (current timeout setting is None) or be aborted by CTRL+C. Auth URI: https://login.microsoftonline.com/123


Viewing all articles
Browse latest Browse all 23305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>