Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keycloak OAuth redirect url combines CHAINTLIT_URL and CHAINLIT_ROOT_PATH #1630

Open
mykemd opened this issue Jan 7, 2025 · 1 comment
Open
Labels
bug Something isn't working needs-triage

Comments

@mykemd
Copy link

mykemd commented Jan 7, 2025

Describe the bug
When Chainlit application is configured behind proxy with custom CHAINLIT_URL and CHAINLIT_ROOT_PATH env environment variables redirect_url parameter for the keycloak authentication has double the root path

To Reproduce
Steps to reproduce the behavior:

  1. configure application to run behind proxy on https://mydomain.com/chainlit-ui path: CHAINLIT_URL=https://mydomain.com/chainlit-ui. CHAINLIT_ROOT_PATH=/chainlit-ui
  2. Add keycloak OAUTH parameters
  3. Run the App and Click on Continue With Keycloak
  4. See network calls in Dev tools - redirect_url parameter for keycloak will double root path https://keycloakbase.com/realms/keycloak_realm/protocol/openid-connect/auth?client_id=keycloal_client_id&redirect_uri=https%3A%2F%2Fmydomain.com%2Fchainlit-ui%2Fchainlit-ui%2Fauth%2Foauth%2Fkeycloak%2Fcallback

Expected behavior
CHAINLIT_ROOT_PATH should not be added to the redirect url

Desktop (please complete the following information):

  • Browser any
@dosubot dosubot bot added the bug Something isn't working label Jan 7, 2025
@mykemd
Copy link
Author

mykemd commented Jan 7, 2025

For now we forked the project and modified this method

def get_user_facing_url(url: URL):
    """
    Return the user facing URL for a given URL.
    Handles deployment with proxies (like cloud run).
    """
    chainlit_url = os.environ.get("CHAINLIT_URL")

    # No config, we keep the URL as is
    if not chainlit_url:
        url = url.replace(query="", fragment="")
        return url.__str__()

    config_url = URL(chainlit_url).replace(
        query="",
        fragment="",
    )
    # Remove trailing slash from config URL
    if config_url.path.endswith("/"):
        config_url = config_url.replace(path=config_url.path[:-1])

    config_url_path = str(config_url)
    url_path = url.path
    chainlit_root = os.environ.get("CHAINLIT_ROOT_PATH")
    if chainlit_root and url_path.startswith(chainlit_root):
        url_path = url_path[len(chainlit_root):]

    return config_url_path + url_path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

No branches or pull requests

1 participant