add user agent to improve compatibility
This commit is contained in:
parent
2037e44736
commit
5636083f2c
2 changed files with 9 additions and 4 deletions
|
@ -55,6 +55,7 @@ def get_relationships(site, id_list, token):
|
|||
url = 'https://' + site + API_GET_RELATIONSHIPS
|
||||
payload = {'id[]': id_list}
|
||||
headers = {
|
||||
'User-Agent': 'NeoDB/1.0',
|
||||
'Authorization': f'Bearer {token}'
|
||||
}
|
||||
response = get(url, headers=headers, params=payload)
|
||||
|
@ -64,6 +65,7 @@ def get_relationships(site, id_list, token):
|
|||
def post_toot(site, content, visibility, token, local_only=False):
|
||||
url = 'https://' + site + API_PUBLISH_TOOT
|
||||
headers = {
|
||||
'User-Agent': 'NeoDB/1.0',
|
||||
'Authorization': f'Bearer {token}',
|
||||
'Idempotency-Key': random_string_generator(16)
|
||||
}
|
||||
|
@ -105,7 +107,7 @@ def create_app(domain_name):
|
|||
payload['redirect_uris'] = 'http://localhost/users/OAuth2_login/\nurn:ietf:wg:oauth:2.0:oob'
|
||||
payload['client_name'] = 'test_do_not_authorise'
|
||||
|
||||
response = post(url, data=payload)
|
||||
response = post(url, data=payload, headers={'User-Agent': 'NeoDB/1.0'})
|
||||
return response
|
||||
|
||||
|
||||
|
@ -117,6 +119,7 @@ def get_site_id(username, user_site, target_site, token):
|
|||
'q': f"{username}@{user_site}"
|
||||
}
|
||||
headers = {
|
||||
'User-Agent': 'NeoDB/1.0',
|
||||
'Authorization': f'Bearer {token}'
|
||||
}
|
||||
response = get(url, params=payload, headers=headers)
|
||||
|
|
|
@ -17,12 +17,12 @@ def obtain_token(site, request, code):
|
|||
'scope': 'read write'
|
||||
}
|
||||
if settings.DEBUG:
|
||||
payload['redirect_uri']= f"http://{request.get_host()}{reverse('users:OAuth2_login')}",
|
||||
payload['redirect_uri'] = f"http://{request.get_host()}{reverse('users:OAuth2_login')}",
|
||||
if mast_app.is_proxy:
|
||||
url = 'https://' + mast_app.proxy_to + API_OBTAIN_TOKEN
|
||||
else:
|
||||
url = 'https://' + mast_app.domain_name + API_OBTAIN_TOKEN
|
||||
response = post(url, data=payload)
|
||||
response = post(url, data=payload, headers={'User-Agent': 'NeoDB/1.0'})
|
||||
if response.status_code != 200:
|
||||
return
|
||||
data = response.json()
|
||||
|
@ -32,6 +32,7 @@ def obtain_token(site, request, code):
|
|||
def get_user_data(site, token):
|
||||
url = 'https://' + site + API_VERIFY_ACCOUNT
|
||||
headers = {
|
||||
'User-Agent': 'NeoDB/1.0',
|
||||
'Authorization': f'Bearer {token}'
|
||||
}
|
||||
response = get(url, headers=headers)
|
||||
|
@ -53,13 +54,14 @@ def revoke_token(site, token):
|
|||
url = 'https://' + mast_app.proxy_to + API_REVOKE_TOKEN
|
||||
else:
|
||||
url = 'https://' + site + API_REVOKE_TOKEN
|
||||
response = post(url, data=payload)
|
||||
response = post(url, data=payload, headers={'User-Agent': 'NeoDB/1.0'})
|
||||
|
||||
|
||||
def verify_token(site, token):
|
||||
""" Check if the token is valid and is of local instance. """
|
||||
url = 'https://' + site + API_VERIFY_ACCOUNT
|
||||
headers = {
|
||||
'User-Agent': 'NeoDB/1.0',
|
||||
'Authorization': f'Bearer {token}'
|
||||
}
|
||||
response = get(url, headers=headers)
|
||||
|
|
Loading…
Add table
Reference in a new issue