mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-17 15:59:04 +00:00
perf: 优化用户 access key 的使用和创建 (#11776)
* perf: 优化用户 access key 的使用和创建 * perf: 优化 access key api --------- Co-authored-by: ibuler <ibuler@qq.com>
This commit is contained in:
0
apps/authentication/tests/__init__.py
Normal file
0
apps/authentication/tests/__init__.py
Normal file
34
apps/authentication/tests/access_key.py
Normal file
34
apps/authentication/tests/access_key.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# Python 示例
|
||||
# pip install requests drf-httpsig
|
||||
import datetime
|
||||
import json
|
||||
|
||||
import requests
|
||||
from httpsig.requests_auth import HTTPSignatureAuth
|
||||
|
||||
|
||||
def get_auth(KeyID, SecretID):
|
||||
signature_headers = ['(request-target)', 'accept', 'date']
|
||||
auth = HTTPSignatureAuth(key_id=KeyID, secret=SecretID, algorithm='hmac-sha256', headers=signature_headers)
|
||||
return auth
|
||||
|
||||
|
||||
def get_user_info(jms_url, auth):
|
||||
url = jms_url + '/api/v1/users/users/?limit=1'
|
||||
gmt_form = '%a, %d %b %Y %H:%M:%S GMT'
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
'X-JMS-ORG': '00000000-0000-0000-0000-000000000002',
|
||||
'Date': datetime.datetime.utcnow().strftime(gmt_form)
|
||||
}
|
||||
|
||||
response = requests.get(url, auth=auth, headers=headers)
|
||||
print(json.loads(response.text))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
jms_url = 'http://localhost:8080'
|
||||
KeyID = '0753098d-810c-45fb-b42c-b27077147933'
|
||||
SecretID = 'a58d2530-d7ee-4390-a204-3492e44dde84'
|
||||
auth = get_auth(KeyID, SecretID)
|
||||
get_user_info(jms_url, auth)
|
Reference in New Issue
Block a user