Skip to content

Commit

Permalink
fix: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
nannan00 committed Dec 10, 2024
1 parent e92b92a commit d86d8b7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/bk-login/bklogin/open_apis/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
path("api/v3/get_user/", compatibility_views.UserRetrieveCompatibilityApi.as_view(api_version="v3")),
# Note: 新的 OpenAPI 后面统一接入 APIGateway,不支持直接调用
# 同时只提供给 APIGateway 做用户认证的接口与通用 OpenAPI 区分开
path("api/v3/open/bk-tokens/introspect/", views.TokenIntrospectApi.as_view(), name="v3_open.bk_token.introspect"),
path("api/v3/open/bk-tokens/verify/", views.TokenVerifyApi.as_view(), name="v3_open.bk_token.verify"),
path(
"api/v3/open/bk-tokens/userinfo-introspect/",
views.TokenUserInfoIntrospectApi.as_view(),
name="v3_open.bk_token.user_introspect",
"api/v3/open/bk-tokens/userinfo/",
views.TokenUserInfoRetrieveApi.as_view(),
name="v3_open.bk_token.userinfo_retrieve",
),
path("api/v3/apigw/bk-tokens/introspect/", views.TokenIntrospectApi.as_view(skip_app_verified=True)),
path("api/v3/apigw/bk-tokens/verify/", views.TokenVerifyApi.as_view(skip_app_verified=True)),
# FIXME (nan): 临时兼容用户管理 SaaS 本地开发的登录
path("api/v3/bkuser/bk-tokens/introspect/", views.TokenIntrospectApi.as_view(skip_app_verified=True)),
path("api/v3/bkuser/bk-tokens/verify/", views.TokenVerifyApi.as_view(skip_app_verified=True)),
path(
"api/v3/bkuser/bk-tokens/userinfo-introspect/",
views.TokenUserInfoIntrospectApi.as_view(skip_app_verified=True),
"api/v3/bkuser/bk-tokens/userinfo/",
views.TokenUserInfoRetrieveApi.as_view(skip_app_verified=True),
),
]
4 changes: 2 additions & 2 deletions src/bk-login/bklogin/open_apis/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .mixins import APIGatewayAppVerifiedMixin


class TokenIntrospectApi(APIGatewayAppVerifiedMixin, View):
class TokenVerifyApi(APIGatewayAppVerifiedMixin, View):
"""Token 解析"""

def get(self, request, *args, **kwargs):
Expand All @@ -42,7 +42,7 @@ def get(self, request, *args, **kwargs):
return APISuccessResponse(data={"bk_username": user.id, "tenant_id": user.tenant_id})


class TokenUserInfoIntrospectApi(APIGatewayAppVerifiedMixin, View):
class TokenUserInfoRetrieveApi(APIGatewayAppVerifiedMixin, View):
"""Token 用户信息解析"""

def get(self, request, *args, **kwargs):
Expand Down
8 changes: 4 additions & 4 deletions src/bk-login/tests/open_apis/test_bk_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _mock_bk_user_component(self):
yield

def test_standard(self, open_api_client, bk_token):
resp = open_api_client.get(reverse("v3_open.bk_token.introspect"), data={"bk_token": bk_token})
resp = open_api_client.get(reverse("v3_open.bk_token.verify"), data={"bk_token": bk_token})

assert resp.status_code == 200

Expand All @@ -58,12 +58,12 @@ def test_standard(self, open_api_client, bk_token):
assert data["tenant_id"] == "test_tenant_id"

def test_invalid(self, open_api_client, bk_token):
resp = open_api_client.get(reverse("v3_open.bk_token.introspect"), data={"bk_token": f"invalid_{bk_token}"})
resp = open_api_client.get(reverse("v3_open.bk_token.verify"), data={"bk_token": f"invalid_{bk_token}"})

assert resp.status_code == 400

def test_userinfo_standard(self, open_api_client, bk_token):
resp = open_api_client.get(reverse("v3_open.bk_token.user_introspect"), data={"bk_token": bk_token})
resp = open_api_client.get(reverse("v3_open.bk_token.userinfo_retrieve"), data={"bk_token": bk_token})

assert resp.status_code == 200

Expand All @@ -76,7 +76,7 @@ def test_userinfo_standard(self, open_api_client, bk_token):

def test_userinfo_invalid(self, open_api_client, bk_token):
resp = open_api_client.get(
reverse("v3_open.bk_token.user_introspect"), data={"bk_token": f"invalid_{bk_token}"}
reverse("v3_open.bk_token.userinfo_retrieve"), data={"bk_token": f"invalid_{bk_token}"}
)

assert resp.status_code == 400
4 changes: 2 additions & 2 deletions src/bk-user/bkuser/component/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def _call_login_api(http_func, url_path, **kwargs):

def verify_bk_token(bk_token: str):
"""验证 bk_token"""
url_path = "api/v3/bkuser/bk-tokens/introspect/"
url_path = "api/v3/bkuser/bk-tokens/verify/"
return _call_login_api(http_get, url_path, params={"bk_token": bk_token})


def get_user_info(bk_token: str):
"""
获取用户信息
"""
url_path = "api/v3/bkuser/bk-tokens/userinfo-introspect/"
url_path = "api/v3/bkuser/bk-tokens/userinfo/"
return _call_login_api(http_get, url_path, params={"bk_token": bk_token})

0 comments on commit d86d8b7

Please sign in to comment.