mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-16 15:28:38 +00:00
perf: OAuth2协议获取token支持配置json或者data (#12602)
* perf: OAuth2协议获取token支持配置json或者data * perf: 优化注释 --------- Co-authored-by: jiangweidong <weidong.jiang@fit2cloud.com>
This commit is contained in:
@@ -98,16 +98,19 @@ class OAuth2Backend(JMSModelBackend):
|
||||
access_token_url = '{url}{separator}{query}'.format(
|
||||
url=settings.AUTH_OAUTH2_ACCESS_TOKEN_ENDPOINT, separator=separator, query=urlencode(query_dict)
|
||||
)
|
||||
# token_method -> get, post(post_data), post_json
|
||||
token_method = settings.AUTH_OAUTH2_ACCESS_TOKEN_METHOD.lower()
|
||||
requests_func = getattr(requests, token_method, requests.get)
|
||||
logger.debug(log_prompt.format('Call the access token endpoint[method: %s]' % token_method))
|
||||
headers = {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
if token_method == 'post':
|
||||
access_token_response = requests_func(access_token_url, headers=headers, data=query_dict)
|
||||
if token_method.startswith('post'):
|
||||
body_key = 'json' if token_method.endswith('json') else 'data'
|
||||
access_token_response = requests.post(
|
||||
access_token_url, headers=headers, **{body_key: query_dict}
|
||||
)
|
||||
else:
|
||||
access_token_response = requests_func(access_token_url, headers=headers)
|
||||
access_token_response = requests.get(access_token_url, headers=headers)
|
||||
try:
|
||||
access_token_response.raise_for_status()
|
||||
access_token_response_data = access_token_response.json()
|
||||
|
Reference in New Issue
Block a user