Incorporating Azure authentication into Streamlit

Hi folks,

I’ve successfully deployed a Streamlit application as an Azure Web App. I’ve set up MS authentication on top of the webapp. How can I use the redirect URI to get the access token? All examples I’ve seen online use Flask in their code, but I’ve read that Streamlit doesn’t play well with Flask.

I figured out how to incorporate Azure authentication. This was how I did it.

def getUserDetails(code):    
    decoded = jwt.decode(code, algorithms=["RS256", ], options={"verify_signature": False})

    return decoded

if "user" not in st.session_state:
    headers = st.context.headers
    code = headers.get("X-Ms-Token-Aad-Access-Token")
    st.session_state.user = {}

    if code:
        decoded = getUserDetails(code)

        st.session_state.user["id"] = decoded["oid"]
        st.session_state.user["displayName"] = decoded["name"]
        st.session_state.user["userPrincipalName"] = decoded["upn"]