diff --git a/01-tutorials/03-AgentCore-identity/05-Outbound_Auth_3lo/chatbot_app_cognito.py b/01-tutorials/03-AgentCore-identity/05-Outbound_Auth_3lo/chatbot_app_cognito.py index b807f2f7..fdcf3d38 100644 --- a/01-tutorials/03-AgentCore-identity/05-Outbound_Auth_3lo/chatbot_app_cognito.py +++ b/01-tutorials/03-AgentCore-identity/05-Outbound_Auth_3lo/chatbot_app_cognito.py @@ -1,4 +1,5 @@ import streamlit as st +import streamlit.components.v1 as components import os import json import requests @@ -17,6 +18,60 @@ CONTEXT_WINDOW = 10 # Number of turns (user+assistant pairs) to include in context +def store_token_in_browser(token: str): + """Store the access token in browser's localStorage using JavaScript.""" + components.html( + f""" + + """, + height=0, + ) + + +def get_token_from_browser(): + """Retrieve the access token from browser's localStorage using JavaScript.""" + token_html = components.html( + """ + + """, + height=0, + ) + return token_html + + +def clear_token_from_browser(): + """Clear the access token from browser's localStorage.""" + components.html( + """ + + """, + height=0, + ) + + def get_streamlit_url(): try: # Read the JSON file @@ -258,6 +313,72 @@ def main(): layout="wide", initial_sidebar_state="expanded", ) + + # Add custom CSS for better styling + st.markdown(""" + + """, unsafe_allow_html=True) + import boto3 # Check if configuration loading failed @@ -304,12 +425,38 @@ def main(): if st.session_state["cognito_access_token"] is None: st.markdown( """ -