From 5ee677da73077940579641254e6b96fa8884922d Mon Sep 17 00:00:00 2001 From: r0ny123 <49360849+r0ny123@users.noreply.github.com> Date: Tue, 8 Sep 2026 16:08:38 +0530 Subject: [PATCH] fix(auth): pass API-key credentials to IAM user lookup --- reai_toolkit/app/services/auth/auth_service.py | 12 +++++++++++- tests/unit/auth/test_service.py | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/reai_toolkit/app/services/auth/auth_service.py b/reai_toolkit/app/services/auth/auth_service.py index 51ee81b..87fb781 100644 --- a/reai_toolkit/app/services/auth/auth_service.py +++ b/reai_toolkit/app/services/auth/auth_service.py @@ -140,7 +140,17 @@ def get_me(self, force_refresh: bool = False) -> User | None: if hasattr(self.sdk_config, "user_agent"): api_client.user_agent = self.sdk_config.user_agent try: - self._user = IAMUsersApi(api_client).get_me() + # The generated IAM operation advertises bearerAuth only, but + # the plugin authenticates with the API key accepted by + # /v2/config. Pass that configured auth setting explicitly so + # /v2/iam/me receives the same Authorization header. + api_key_auth = self.sdk_config.auth_settings().get("APIKey") + if api_key_auth: + self._user = IAMUsersApi(api_client).get_me( + _request_auth=api_key_auth + ) + else: + self._user = IAMUsersApi(api_client).get_me() except Exception as e: logger.error(f"RevEng.AI: Failed to fetch current user: {e}") self._user = None diff --git a/tests/unit/auth/test_service.py b/tests/unit/auth/test_service.py index 300e2d4..f93063e 100644 --- a/tests/unit/auth/test_service.py +++ b/tests/unit/auth/test_service.py @@ -121,6 +121,16 @@ def test_get_me_returns_user_and_caches(service, iam_api): iam_api.get_me.assert_called_once() +def test_get_me_uses_configured_api_key_auth(service, iam_api): + iam_api.get_me.return_value = _user("ENTHUSIAST") + + service.get_me() + + iam_api.get_me.assert_called_once_with( + _request_auth=service.sdk_config.auth_settings()["APIKey"] + ) + + def test_get_me_force_refresh_refetches(service, iam_api): iam_api.get_me.side_effect = [_user("ENTHUSIAST"), _user("REVERSER")]