Unable to authenticate using keycloak

I am working on a multipage streamlit app to be authenticated using Keycloak. I have created a file called authenticate.py whose contents are as follows:

from dataclasses import asdict
from streamlit_keycloak import login

def keycloak_auth():
    keycloak=login(url=<my keycloak url>,
    realm="myrealm",
    client_id="test",
    auto_refresh=False,
    custom_labels={
        "labelButton": "Sign in",
        "labelLogin": "Please sign in",
        "errorNoPopup": "Unable to open the auth popup. Allow popup and refresh",
        "errorPopupClosed": "Auth popup closed manually",
        "errorFatal": "Unable to connect to keycloak"
        
    })
    return keycloak

The excerpt from my main page is as follows:

import streamlit as st
st.set_page_config(
    page_title="test",
    layout="wide",
    initial_sidebar_state="expanded",
)

import pandas as pd
from auth import authenticate

keycloak=authenticate.keycloak_auth()

if keycloak.authenticated:
    st.write("authenticated!!!!!!!")
else
    st.write("authentication failed")

I have containerised the application and deployed. When I try to access the application, I get the error authentication failed and later the message comes Unable to connect to keycloak.

Please help me to resolve this issue.

1 Like

Hi viji_narayan,

This is probably an issue with your Keycloak configuration. Recently I’ve updated the readme with a minimal example, which might help getting everything running. Check it out here.

I tried to lower all security measures in a local Docker KeyCloak, turned CORS off in the Streamlit configuration. Still hitting CORS error in Chrome. Firefox gets further, but that flow also dies in svelte’s guts. From KeyCloak server’s point of view the logins are successful.