infiniflow/ragflow · error · ValueError

Invalid channel name: {channel}

Error message

Invalid channel name: {channel}

What it means

Raised by the OAuth callback route GET /auth/oauth/<channel>/callback when the channel has no entry in settings.OAUTH_CONFIG — the provider that initiated the flow is not (or no longer) configured by the time the provider redirects back. Distinct from invalid_state/missing_code redirects: this fails provider resolution itself.

Source

Thrown at api/apps/restful_apis/user_api.py:187

        raise ValueError(f"Invalid channel name: {channel}")
    auth_cli = get_auth_client(channel_config)

    state = get_uuid()
    session["oauth_state"] = state
    auth_url = auth_cli.get_authorization_url(state)
    logging.info("OAuth login initiated: channel='%s', state='%s'", channel, state)
    return redirect(auth_url)


@manager.route("/auth/oauth/<channel>/callback", methods=["GET"])  # noqa: F821
async def oauth_callback(channel):
    """
    Handle the OAuth/OIDC callback for various channels dynamically.
    """
    try:
        channel_config = settings.OAUTH_CONFIG.get(channel)
        if not channel_config:
            raise ValueError(f"Invalid channel name: {channel}")
        auth_cli = get_auth_client(channel_config)

        # Check the state
        state = request.args.get("state")
        if not state or state != session.get("oauth_state"):
            return redirect("/?error=invalid_state")
        session.pop("oauth_state", None)

        # Obtain the authorization code
        code = request.args.get("code")
        if not code:
            return redirect("/?error=missing_code")

        # Exchange authorization code for access token
        if hasattr(auth_cli, "async_exchange_code_for_token"):
            token_info = await auth_cli.async_exchange_code_for_token(code)
        else:
            token_info = auth_cli.exchange_code_for_token(code)

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Ensure the channel key in OAUTH_CONFIG matches the channel segment of the callback URL registered at the provider.
  2. Redo the login flow from scratch after config changes (old states/sessions are invalid anyway).
  3. Check the provider's authorized redirect URI exactly matches /api/v1/auth/oauth/<channel>/callback.
  4. Restart the API server after editing OAuth settings so OAUTH_CONFIG reloads.
Defensive patterns

Strategy: validation

Validate before calling

from api import settings

def callback_configured(channel: str) -> bool:
    return channel in (settings.OAUTH_CONFIG or {})

# before sending the user to the provider:
assert callback_configured(channel), f"callback for '{channel}' will fail - provider not configured"

Try / catch

try:
    result = await handle_oauth_callback(channel, request.args)
except ValueError as e:
    if "Invalid channel name" in str(e):
        return redirect("/?error=unconfigured_channel")
    raise

Prevention

When it happens

Trigger: Provider redirects to /auth/oauth/<channel>/callback with a channel name not in OAUTH_CONFIG — e.g. config changed between login start and callback, the callback URL registered with the provider uses a different channel key, or a stale/misrouted redirect.

Common situations: Editing OAuth settings while a flow is in flight, registering the callback URL in Google/GitHub with a misspelled channel, or deployments where the callback host routes to an instance with different config.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/7c6127616f949135. Report an issue: GitHub.