Streamlit SSO Integration

Is there a builtin support for streamlit to integrate with ping federate SSO? I was doing some research and see if the user is accessing for the first time to redirect to another url, I couldnt find a way to doi it in streamlit.

There is no out of the box native solution. I have solved this by doing the following
This code executes once at the start of the session

sso_url = (f"{sso_host}/as/authorization.oauth2?"
f"client_id={credentials[‘client_id’]}&"
f"response_type=code&"
f"redirect_uri={settings.PING_REDIRECT_URL}“)
redirect_html = f”“”“”"
st.write(redirect_html, unsafe_allow_html=True)


Then in the redirect page

token_url = f"{sso_host}/as/token.oauth2"
headers = {‘Content-Type’: ‘application/x-www-form-urlencoded’}
data = {
‘grant_type’: ‘authorization_code’,
‘code’: code,
‘redirect_uri’: settings.PING_REDIRECT_URL,
‘client_id’: credentials[‘client_id’],
‘client_secret’: credentials[‘client_secret’]
}
response = asyncio.run(post(endpoint=token_url, body_payload=data, headers=headers))
json_response = response.json()
access_token = json_response.get(‘access_token’)
st.session_state.token = access_token
st.switch_page(“Home.py”)
Once I get the access token I am able to call with that token to get the user info.


Would be nice if st.login could handle this pattern. If anyone knows how to replicate this in st.login please post.