[BUG] Keycloak provider substitutes 'no-audience-provided', so every login fails audience validation

Đang mở
#9,817 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Kiko0301 đang làm issue này rồi.

Từ ngày 26/11/2026.

  • #9822 của @Kiko0301 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
authentication

Hướng nghiên cứu

Read lib/crewai-core/src/crewai_core/auth/providers/keycloak.py and compare KeycloakProvider.get_audience() with the providers named in the issue. Trace how the audience reaches _get_device_code and validate_jwt_token to understand the failure. Done means a missing audience is reported before browser login, with a focused test covering the Keycloak behavior.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

KeycloakProvider.get_audience() in lib/crewai-core/src/crewai_core/auth/providers/keycloak.py returns the literal string "no-audience-provided" when no audience is configured:

    def get_audience(self) -> str:
        return self.settings.audience or "no-audience-provided"

That value is not a placeholder kept local to the provider: it is sent as the audience of the device-code request (crewai_core/auth/oauth2.py, _get_device_code) and then passed to PyJWT as the expected aud when the token is validated (_validate_and_save_token -> auth/utils.py::validate_jwt_token, which calls jwt.decode(..., audience=audience, ...)).

A Keycloak access token's aud is its client id or account; it can never equal "no-audience-provided". A Keycloak user who does not configure an audience therefore completes the browser step and then gets:

Exception: Invalid token audience. Got: 'account'. Expected: 'no-audience-provided'

get_required_fields() for Keycloak lists only realm, so nothing rejects the configuration earlier, and unlike Auth0/Okta/Entra ID (auth0.py, okta.py, entra_id.py all raise ValueError("Audience is required. ...") from get_audience()), Keycloak silently substitutes a value that cannot validate.

Steps to Reproduce

from crewai_core.auth.oauth2 import Oauth2Settings
from crewai_core.auth.providers.keycloak import KeycloakProvider

provider = KeycloakProvider(
    Oauth2Settings(
        provider="keycloak",
        domain="keycloak.example.com",
        client_id="crewai-cli",
        audience=None,
        extra={"realm": "my-realm"},
    )
)
print(provider.get_audience())

Actual output:

no-audience-provided

Expected Behavior

get_audience() should report the missing setting, as the other providers do, instead of returning a value that makes every login fail at the last step with a misleading error. crewai enterprise login should say that an audience is required before opening the browser.

AI assistance

I used an AI coding agent to investigate, reproduce, and prepare this report, and reviewed its results. Per CONTRIBUTING.md, please apply the llm-generated label; external contributors cannot add it with my current permissions.

Ngôn ngữ chính
Python
Star
61.2k
Fork
9.2k
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
180

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của crewAIInc/crewAI

Tất cả issue của crewAIInc/crewAI

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.