Skip to content

Commit 2ee4bc0

Browse files
authored
fix(bkpaas-auth): 修复通过 APIGatewayAuthBackend 认证无法获取 tenant_id 问题 (TencentBlueKing#230)
1 parent 59a95e2 commit 2ee4bc0

5 files changed

Lines changed: 24 additions & 8 deletions

File tree

sdks/bkpaas-auth/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 版本历史
22

3+
## 3.1.2
4+
- fix: 修复通过 APIGatewayAuthBackend 认证无法获取 tenant_id 的问题
5+
36
## 3.1.1
47
- fix: 修复 apigw-manager 4.0.1 版本 JWT 中间件新增 tenant_id 参数导致的 JWT 认证失效问题
58

sdks/bkpaas-auth/bkpaas_auth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = "3.1.1"
2+
__version__ = "3.1.2"
33

44

55
def get_user_by_user_id(user_id: str, username_only: bool = True):

sdks/bkpaas-auth/bkpaas_auth/backends.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,26 +208,39 @@ class APIGatewayAuthBackend:
208208

209209
_TOKEN_EXPIRE_TIME = 86400 # 24 hours in seconds
210210

211-
def _create_authenticated_user(self, username: str, provider_type: ProviderType) -> User:
211+
def _create_authenticated_user(
212+
self, username: str, provider_type: ProviderType, tenant_id: str | None = None
213+
) -> User:
212214
"""Create a user object for authenticated requests."""
213215
return User(
214216
token=LoginToken("any_token", expires_in=self._TOKEN_EXPIRE_TIME),
215217
provider_type=provider_type,
216218
username=username,
219+
tenant_id=tenant_id,
217220
)
218221

219-
def _authenticate_common(self, verified: bool, username: Optional[str]) -> Union[User, AnonymousUser]:
222+
def _authenticate_common(
223+
self, verified: bool, username: str | None = None, tenant_id: str | None = None
224+
) -> Union[User, AnonymousUser]:
220225
"""Common authentication logic for all versions."""
221226
if not verified or not username:
222227
return self.make_anonymous_user(username)
223228

224-
return self._create_authenticated_user(username=username, provider_type=self.get_provider_type())
229+
return self._create_authenticated_user(
230+
username=username, provider_type=self.get_provider_type(), tenant_id=tenant_id
231+
)
225232

226233
def authenticate_with_signature_v3(
227-
self, request: HttpRequest, gateway_name: str, bk_username: str, verified: bool, **credentials: Dict
234+
self,
235+
request: HttpRequest,
236+
gateway_name: str,
237+
bk_username: str,
238+
tenant_id: str,
239+
verified: bool,
240+
**credentials: Dict,
228241
) -> Union[User, AnonymousUser]:
229242
"""authenticate function with signature required by ApiGatewayJWTUserMiddleware in apigw_manager == '^3.0.0'"""
230-
return self._authenticate_common(verified, bk_username)
243+
return self._authenticate_common(verified, bk_username, tenant_id)
231244

232245
def authenticate_with_signature_v1(
233246
self, request: HttpRequest, api_name: str, bk_username: str, verified: bool, **credentials: Dict

sdks/bkpaas-auth/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "bkpaas-auth"
3-
version = "3.1.1"
3+
version = "3.1.2"
44
description = "User authentication django app for blueking internal projects"
55
readme = "README.md"
66
authors = ["blueking <blueking@tencent.com>"]

sdks/bkpaas-auth/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
setup(
2424
long_description=readme,
2525
name="bkpaas-auth",
26-
version="3.1.1",
26+
version="3.1.2",
2727
description="User authentication django app for blueking internal projects",
2828
python_requires="<4.0,>=3.8",
2929
author="blueking",

0 commit comments

Comments
 (0)