Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move authentication data to header X-Bkapi-Authorization #141

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdks/bkpaas-auth/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 版本历史

## 2.0.7
- 将认证信息标准化到请求头 X-Bkapi-Authorization 中

## 2.0.6
- TokenRequestBackend.request_username 支持国际化

Expand Down
12 changes: 9 additions & 3 deletions sdks/bkpaas-auth/bkpaas_auth/core/services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import json
import logging
from typing import Dict

Expand All @@ -11,6 +12,7 @@
from bkpaas_auth.core.user_info import BkUserInfo, RtxUserInfo
from bkpaas_auth.utils import scrub_data


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -38,14 +40,18 @@ def _get_and_cache_user_info(cache_key, user_params, response_ok_checker):
if cached_result:
return cached_result

params = dict(user_params, **get_app_credentials())
is_success, result = http_get(conf.TOKEN_USER_INFO_ENDPOINT, params=params)
is_success, result = http_get(
conf.TOKEN_USER_INFO_ENDPOINT,
headers={
"X-Bkapi-Authorization": json.dumps(dict(user_params, **get_app_credentials())),
},
)
if not is_success:
raise ServiceError('Unable to get user info')

if not response_ok_checker(result):
logger.error(
f'Get user info fail, url: {conf.TOKEN_USER_INFO_ENDPOINT}, params: {scrub_data(params)}'
f'Get user info fail, url: {conf.TOKEN_USER_INFO_ENDPOINT}, params: {scrub_data(user_params)}'
piglei marked this conversation as resolved.
Show resolved Hide resolved
f', response: {result}',
)
return
Expand Down
7 changes: 5 additions & 2 deletions sdks/bkpaas-auth/bkpaas_auth/core/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Access token for blueking
"""
import datetime
import json
import logging

from django.utils.timezone import now
Expand Down Expand Up @@ -32,9 +33,11 @@ def request_username(self, **credentials):
"""Get username through credentials"""
is_success, resp = http_get(
bkauth_settings.USER_COOKIE_VERIFY_URL,
params=dict(credentials, **get_app_credentials()),
timeout=10,
headers={'blueking-language': get_language()},
headers={
'blueking-language': get_language(),
"X-Bkapi-Authorization": json.dumps(dict(credentials, **get_app_credentials())),
},
)
if not is_success:
raise ServiceError('unable to fetch token services')
Expand Down
Loading