forked from phoenix-oss/llama-stack-mirror
add keycloak auth to playground ui
This commit is contained in:
parent
ed31462499
commit
3bde47e562
5 changed files with 38 additions and 1 deletions
|
@ -50,6 +50,36 @@ def main():
|
|||
)
|
||||
pg.run()
|
||||
|
||||
def main2():
|
||||
from dataclasses import asdict
|
||||
st.subheader(f"Welcome {keycloak.user_info['preferred_username']}!")
|
||||
st.write(f"Here is your user information:")
|
||||
st.write(asdict(keycloak))
|
||||
|
||||
def get_access_token() -> str|None:
|
||||
return st.session_state.get('access_token')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
from streamlit_keycloak import login
|
||||
import os
|
||||
|
||||
keycloak_url = os.environ.get("KEYCLOAK_URL")
|
||||
keycloak_realm = os.environ.get("KEYCLOAK_REALM", "default")
|
||||
keycloak_client_id = os.environ.get("KEYCLOAK_CLIENT_ID")
|
||||
|
||||
if keycloak_url and keycloak_client_id:
|
||||
keycloak = login(
|
||||
url=keycloak_url,
|
||||
realm=keycloak_realm,
|
||||
client_id=keycloak_client_id,
|
||||
auto_refresh=True,
|
||||
init_options={"checkLoginIframe": False},
|
||||
)
|
||||
|
||||
if keycloak.authenticated:
|
||||
st.session_state['access_token'] = keycloak.access_token
|
||||
main()
|
||||
# TBD - add other authentications
|
||||
else:
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue