ruvnet/RuView · error · HTTPException

Authentication required

Error message

Authentication required

What it means

get_current_active_user raises 401 'Authentication required' when its dependency get_current_user resolved to None, which happens when authentication is enabled but the request carried no credentials at all. Endpoints depending on get_current_active_user require a bearer token.

Source

Thrown at archive/v1/src/api/dependencies.py:117

    # In production, implement proper JWT validation
    raise HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail=(
            "JWT authentication is not configured. Configure JWT_SECRET and "
            "JWT_ALGORITHM environment variables, or integrate an external "
            "identity provider. See docs/authentication.md for setup instructions."
        ),
        headers={"WWW-Authenticate": "Bearer"},
    )


async def get_current_active_user(
    current_user: Optional[Dict[str, Any]] = Depends(get_current_user)
) -> Dict[str, Any]:
    """Get current active user (required authentication)."""
    if not current_user:
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Authentication required",
            headers={"WWW-Authenticate": "Bearer"},
        )
    
    # Check if user is active
    if not current_user.get("is_active", True):
        raise HTTPException(
            status_code=status.HTTP_403_FORBIDDEN,
            detail="Inactive user"
        )
    
    return current_user


async def get_admin_user(
    current_user: Dict[str, Any] = Depends(get_current_active_user)
) -> Dict[str, Any]:

View on GitHub (pinned to 4685618388)

Solutions

  1. Send Authorization: Bearer <token> on the request
  2. Obtain a token through the login flow first, then call the protected endpoint
  3. If the endpoint should permit anonymous access, depend on get_current_user (Optional) instead of get_current_active_user
  4. Verify proxies/gateways forward the Authorization header

Example fix

# before
curl http://api/zones/alpha/pose
# -> 401 Authentication required

# after
curl -H 'Authorization: Bearer <token>' http://api/zones/alpha/pose
Defensive patterns

Strategy: validation

Validate before calling

# Client-side: never call a protected route without a token
def call_protected(client, token, url):
    if not token:
        raise ValueError('No bearer token available; authenticate before calling protected endpoints')
    return client.get(url, headers={'Authorization': f'Bearer {token}'})

Try / catch

try:
    r = client.get('/api/protected', headers=auth_headers())
    r.raise_for_status()
except httpx.HTTPStatusError as e:
    if e.response.status_code == 401:
        # refresh token / redirect to login, then retry once
        token = refresh_login()
        r = client.get('/api/protected', headers={'Authorization': f'Bearer {token}'})
    else:
        raise

Prevention

When it happens

Trigger: Calling a protected route without an Authorization header; a proxy stripping the Authorization header before it reaches FastAPI; a frontend fetch that has not attached the token yet; curl/httpx calls that omit credentials.

Common situations: Session expired and the client silently stopped sending the token; gateway configured to drop auth headers; API exploration with curl without -H 'Authorization: Bearer ...'.

Understand the failure class

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/6e9ec2b540a9eb74. Report an issue: GitHub.