bleumink / streamlit-keycloak

User authentication and single sign-on in your Streamlit app using Keycloak
MIT License
59 stars 11 forks source link

Unable to connect to Keycloak using the current configuration. #6

Closed bqueguin closed 1 year ago

bqueguin commented 1 year ago

Hi,

I just try to use your tool with a local instance of Keycloak 20.0.1 I created a new realm called DEV and a client called my_client.

Here is my code:

from streamlit_keycloak import login
import streamlit as st

def main():
    st.subheader(f"Welcome {keycloak.user_info['preferred_username']}!")
    st.write(f"Here is your OAuth2 token: {keycloak.access_token}")

st.title("Streamlit Keycloak example")
keycloak = login(
    url="http://localhost:8080",
    realm="DEV",
    client_id="my_client",
)

if keycloak.authenticated:
    main()

But I have the streamlit error message: Unable to connect to Keycloak using the current configuration.

Do you have any idea of what can be the problem?

Cheers Bruno

bleumink commented 1 year ago

Hi Bruno,

Thanks for giving the tool a try. This error message appears when keycloak-js fails to initialize in the frontend, e.g. when it can't connect to the realm or client.

How have you set the client's access type? This should be set to public.

Kind regards, Gideon

On Sun, 20 Nov 2022, 03:09 Bruno QUEGUINER, @.***> wrote:

Hi,

I just try to use your tool with a local instance of Keycloak 20.0.1 I created a new realm called DEV and a client called my_client.

Here is my code:

from streamlit_keycloak import loginimport streamlit as st

def main(): st.subheader(f"Welcome {keycloak.user_info['preferred_username']}!") st.write(f"Here is your OAuth2 token: {keycloak.access_token}")

st.title("Streamlit Keycloak example")keycloak = login( url="http://localhost:8080", realm="DEV", client_id="my_client", ) if keycloak.authenticated: main()

But I have the streamlit error message: Unable to connect to Keycloak using the current configuration.

Do you have any idea of what can be the problem?

Cheers Bruno

— Reply to this email directly, view it on GitHub https://github.com/bleumink/streamlit-keycloak/issues/6, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEXKX5XVDYGF5OL7S4JLSVLWJGB43ANCNFSM6AAAAAASFTIIUU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

bqueguin commented 1 year ago

Hi Gideon,

Thanks for your response.

I just left the default configuration on Keycloak. I can see that the client's access should be public:

image

I am a noob with Keycloak so maybe I am not looking at the good parameter...

Bruno

bqueguin commented 1 year ago

An additional remark on my case:

When I add the following init_options parameter, I don't have the error but I don't have either the display of the connexion window, nothing happen actually.

keycloak = login(
    url="http://localhost:8080",
    realm="DEV",
    client_id="my_client",
    init_options={
        "checkLoginIframe": False
    }
)
bleumink commented 1 year ago

For a valid configuration, you should also set a redirect url and web origin for the client.

When running locally the following should work:

It's recommended to set the web origin as specific as possible. For testing the wildcard * would work fine, but it's not ideal in production.

On Sun, 20 Nov 2022, 04:57 Bruno QUEGUINER, @.***> wrote:

An additional remark on my case:

When I add the following init_options parameter, I don't have the error but I don't have either the display of the connexion window, nothing happen actually.

keycloak = login( url="http://localhost:8080", realm="DEV", client_id="my_client", init_options={ "checkLoginIframe": False } )

— Reply to this email directly, view it on GitHub https://github.com/bleumink/streamlit-keycloak/issues/6#issuecomment-1321028783, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEXKX5RPNIA7DUUQZM2UNVLWJGOTJANCNFSM6AAAAAASFTIIUU . You are receiving this because you commented.Message ID: @.***>

bqueguin commented 1 year ago

You're right, it works now. Thank you so much!

image