bleumink / streamlit-keycloak

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

Sign In Button not showing up #33

Open Alex-Dee opened 4 months ago

Alex-Dee commented 4 months ago

Hi, thanks for the great component. I'm trying to get it running but have the problem that the sign in button /widget is not showing upon when calling login(). Also no erros message is shown, the page just stays blank. Im using the example code from the repo, only with changes to realm and client names. I am using streamlit version 1.35. Hope you can help me with this issue.

image

from dataclasses import asdict
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 user information:")
    st.write(asdict(keycloak))

st.title("Streamlit Keycloak example")
keycloak = login(
    url="http://localhost:8089",
    realm="myrealm",
    client_id="myclient",
)

if keycloak.authenticated:
    main()

Cheers

be-michael-tesar commented 1 month ago

Hi, I'm experiencing the same issue. I'm using streamlit-keycloak version 1.1.1 and encountering the same problem. Clearing the cookies in both the Streamlit app and Keycloak didn't resolve it.

be-michael-tesar commented 1 month ago

@Alex-Dee this worked for me:

login(
        url=settings.keycloak_url,
        realm=settings.keycloak_realm,
        client_id=settings.keycloak_client_id,
        init_options={"checkLoginIframe": True},
        auto_refresh=True,
        custom_labels={
            "labelButton": "Sign in",
            "labelLogin": "Please sign in to your account.",
            "errorNoPopup": "Unable to open the authentication popup. Allow popups and refresh the page to proceed.",
            "errorPopupClosed": "Authentication popup was closed manually.",
            "errorFatal": "Unable to connect to Keycloak using the current configuration.",
        },
    )

Plus, I had to adjust KeyCloak realm configuration in Realm settings - Security defences - Content-Security-Policy - frame-src 'self'; frame-ancestors 'self' <your URL here>; object-src 'none';

cnangel commented 1 month ago

@Alex-Dee this worked for me:

login(
        url=settings.keycloak_url,
        realm=settings.keycloak_realm,
        client_id=settings.keycloak_client_id,
        init_options={"checkLoginIframe": True},
        auto_refresh=True,
        custom_labels={
            "labelButton": "Sign in",
            "labelLogin": "Please sign in to your account.",
            "errorNoPopup": "Unable to open the authentication popup. Allow popups and refresh the page to proceed.",
            "errorPopupClosed": "Authentication popup was closed manually.",
            "errorFatal": "Unable to connect to Keycloak using the current configuration.",
        },
    )

Plus, I had to adjust KeyCloak realm configuration in Realm settings - Security defences - Content-Security-Policy - frame-src 'self'; frame-ancestors 'self' <your URL here>; object-src 'none';

what's your keycloak version?

be-michael-tesar commented 1 month ago

@Alex-Dee this worked for me:

login(
        url=settings.keycloak_url,
        realm=settings.keycloak_realm,
        client_id=settings.keycloak_client_id,
        init_options={"checkLoginIframe": True},
        auto_refresh=True,
        custom_labels={
            "labelButton": "Sign in",
            "labelLogin": "Please sign in to your account.",
            "errorNoPopup": "Unable to open the authentication popup. Allow popups and refresh the page to proceed.",
            "errorPopupClosed": "Authentication popup was closed manually.",
            "errorFatal": "Unable to connect to Keycloak using the current configuration.",
        },
    )

Plus, I had to adjust KeyCloak realm configuration in Realm settings - Security defences - Content-Security-Policy - frame-src 'self'; frame-ancestors 'self' <your URL here>; object-src 'none';

what's your keycloak version?

JaworIwanowRoosi commented 1 month ago

@Alex-Dee this worked for me:

login(
        url=settings.keycloak_url,
        realm=settings.keycloak_realm,
        client_id=settings.keycloak_client_id,
        init_options={"checkLoginIframe": True},
        auto_refresh=True,
        custom_labels={
            "labelButton": "Sign in",
            "labelLogin": "Please sign in to your account.",
            "errorNoPopup": "Unable to open the authentication popup. Allow popups and refresh the page to proceed.",
            "errorPopupClosed": "Authentication popup was closed manually.",
            "errorFatal": "Unable to connect to Keycloak using the current configuration.",
        },
    )

Plus, I had to adjust KeyCloak realm configuration in Realm settings - Security defences - Content-Security-Policy - frame-src 'self'; frame-ancestors 'self' <your URL here>; object-src 'none';

what's your keycloak version?

* `streamlit`: `1.36.0`

* `streamlit-keycloak`: `1.1.1`

Having the same issue and the dependencies and configuration sadly did not work for me.

be-michael-tesar commented 1 month ago

@JaworIwanowRoosi could be the KeyCloak settings? Have you opened your browser DevTools for any errors?

JaworIwanowRoosi commented 1 month ago

@JaworIwanowRoosi could be the KeyCloak settings? Have you opened your browser DevTools for any errors?

Thank you very much vor the quick reply! I'm somewhat confident, that the config is correct, as I've followed the guides/readmes and trying to mess with the settings results in "Timeout when waiting for 3rd party check iframe message." errors.

The devtools do catch an error;

GET [http://localhost:8080/realms/local/protocol/openid-connect/login-status-iframe.html/init?client_id=localclient&origin=http://localhost:8085]
(http://localhost:8080/realms/local/protocol/openid-connect/login-status-iframe.html/init?client_id=localclient&origin=http%3A%2F%2Flocalhost%3A8085)
[HTTP/1.1 403 Forbidden 12ms]

Uncaught (in promise) TypeError: t[18] is undefined

http://localhost:8085 is added to the content-security-policy.

be-michael-tesar commented 1 month ago

It looks good to me, I am unsure what may the problem at this moment.

JaworIwanowRoosi commented 1 month ago

Got it to work by setting the valid redirect uris and weborigins both to accept everything through the * wildcard. No variation of localhost settings seemed to work, though I'm running WSL and I've had issues with localhost/host.docker.internal before.